Change the properties of a custom post type after it’s been registered?

While it’s possible to manipulate CPT data after registration it’s not very “clean” and harder for some things. Specifically for hierarchical setting registration adds it to rewrite right away: if ( $args->hierarchical ) add_rewrite_tag( “%$post_type%”, ‘(.+?)’, $args->query_var ? “{$args->query_var}=” : “post_type=$post_type&pagename=” ); else add_rewrite_tag( “%$post_type%”, ‘([^/]+)’, $args->query_var ? “{$args->query_var}=” : “post_type=$post_type&name=” ); So you’ll have … Read more

custom taxonomy listing returns no posts

Answer moved from an edit in the answer to a real answer. This is my query <?php $taxonomy = (get_post_type() == ‘post’ ? ‘category’ : (get_post_type() == ‘news’ || is_tax(‘news_categories’) ? ‘news_categories’ : ‘category’)); $tax_terms = get_terms($taxonomy, array(‘hide_empty’=> false) ); global $wp_query; if( isset($_GET[‘s’]) ): $wp_query->is_search = true; endif; // var_dump($activeCategoryName = $wp_query->queried_object); if(is_tax(‘news_categories’)) { … Read more

“Cannot redeclare cpt_reg_tax()” because of functions.php

You cannot use the same function name more than once. Give the second function a different name: add_action( ‘wp_loaded’, ‘cpt_reg_tax1’ ); function cpt_reg_tax1() { // code for the first taxonomy here } add_action( ‘wp_loaded’, ‘cpt_reg_tax2’ ); function cpt_reg_tax2() { // code for the second taxonomy here } Besides that, your code will terrible break for … Read more

Change permalinks for custom post type based on taxonomy term

Use Category base and Tag base Permalink The Category base and Tag base are prefixes used in URLs for category and tag archives, which look like this: example.net/wp/category_base/category_name example.net/wp/tag_base/tag_name The default values for these are category and tag. You can change them, but you can’t remove them from the URLs altogether. Custom permalinks work on … Read more

Custom Post Type Specific Post Template

For some reason wordpress don’t honor Template_Hierarchy. The best way to get around this problem is to “force” wordpress to use the custom single.php template that you created. To accomplish that, add the following function underneath your CPT. /* Information Posts Template selection – a single.php just for our wrestler_profiles */ function pietergoosen_info_template_include( $original_template ) … Read more