Clean Custom URL for Serach + Custom Taxonomy

With Slam’s kind tip to use query-monitor plugin, I could figure out what the problem was. Apparently the url /search/foo/filter/bar also fits the “general search” rewrite-rule. Makes sense, thinking about it– (.+) technically matches /foo/filter/bar aswell. So I could improve (.+) by excluding /s? But I found an easier solution! In hope “first match wins” …

Read more

Custom post type and custom taxonomy 404 on page 2

So after many trials and errors, I found I had to create a specific rewrite rule to go into my functions.php, one that handles post type ‘videos‘ and the category (taxonomy) ‘videos_category‘: add_filter(‘init’, function() { add_rewrite_rule( ‘^videos/([^/]*)/([^/]*)/(\d*)?’, ‘index.php?videos_category=$matches[1]&p=$matches[2]&paged=$matches[3]’, ‘top’ ); }); I also found this plugin to be really helpful for viewing my rewrite rules: …

Read more

Custom taxonomy link automatically removing query string and re-directing

WordPress uses the redirect_canonical function in order to ensure that URLs are properly following the current permalink structure: https://codex.wordpress.org/Function_Reference/redirect_canonical The function is hooked to automatically run on the template_redirect filter. In order to remove it, you need to add the following snippet to your theme or plugin: remove_filter( ‘template_redirect’, ‘redirect_canonical’ ); Keep in mind that …

Read more

Loop to display ONLY custom taxonomy parent information [closed]

I believe this has already been answered perfectly in How can I get only parent terms?. The solution is to set ‘parent’ => 0 when querying terms with get_terms() or WP_Term_Query. The example from that question looked like this: $myterms = get_terms( array( ‘taxonomy’ => ‘taxonomy_name’, ‘parent’ => 0 ) ); You can easily loop …

Read more

Query custom post types & Taxonomies and list them in a table on a page

You can use term_query in WP_Query: $args = array( ‘post_type’ => ‘all_parks’, ‘posts_per_page’ => -1, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘all_park_categories’, ‘field’ => ‘slug’, ‘terms’ => ‘national_parks’, ), ), ); $all_parks = new WP_Query( $args ); Query all posts with all categories and sort by term or create …

Read more