Inventory_Presser_Plugin::generate_rewrite_rules( string $post_type, array $query_vars = array() )
Generate every possible combination of rewrite rules, including paging, based on post type taxonomy
On This Page
Description Description
See also See also
Parameters Parameters
- $post_type
-
(string) (Required) The name of a post type.
- $query_vars
-
(array) (Optional) An array of query variables.
Default value: array()
Return Return
(array)
Source Source
File: inventory-presser.php
$sites = get_sites( array( 'network' => 1, 'limit' => apply_filters( 'invp_query_limit', 1000, __METHOD__ ), ) ); foreach ( $sites as $site ) { switch_to_blog( $site->blog_id ); global $wp_rewrite; $wp_rewrite->init(); // important... $wp_rewrite->flush_rules(); restore_current_blog(); } } /** * Generate every possible combination of rewrite rules, including paging, based on post type taxonomy * * @see https://thereforei.am/2011/10/28/advanced-taxonomy-queries-with-pretty-urls/ * * @param string $post_type The name of a post type. * @param array $query_vars An array of query variables. * @return array */ protected function generate_rewrite_rules( $post_type, $query_vars = array() ) { global $wp_rewrite; if ( ! is_object( $post_type ) ) { $post_type = get_post_type_object( $post_type ); } $rewrite_slugs = apply_filters( 'invp_rewrite_slugs', array( $post_type->rewrite['slug'], ) ); $taxonomies = get_object_taxonomies( $post_type->name, 'objects' ); $new_rewrite_rules = array(); // Add taxonomy filters to the query vars array. foreach ( $taxonomies as $taxonomy ) { $query_vars[] = $taxonomy->query_var; } // Loop over all the possible combinations of the query vars. $query_vars_count = count( $query_vars ); for ( $i = 1; $i <= $query_vars_count; $i++ ) {
Expand full source codeCollapse full source codeView on Github