Exclude a term of a taxonomy with a custom post type in a search

The problem with your approach is that woocommerces product category is a custom taxonomy called product_cat. But with cat you are addressing the built-in category. Taxonomies can be addressed with a tax query, simplified example below: function wpse188669_pre_get_posts( $query ) { if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { $query->set( ‘post_type’, array( ‘product’ … Read more

Disable Single Post View for Specific Taxonomy on Custom Post Type

I use template_redirect hook for this purpose. I suppose rented in your question is not taxonomy itself, but one term of some taxonomy. function my_page_template_redirect() { if( is_singular( ‘rentals’ ) && has_term(‘rented’, ‘your taxonomy name’) ) { wp_redirect( home_url(), 301 ); exit(); } } add_action( ‘template_redirect’, ‘my_page_template_redirect’ ); Before page rendering, WP checks if CPT … Read more

Pagination not working with custom category template

As this is your main loop of your template, you should not be making a new loop, but modify the existing loop with pre_get_posts. This way you can be sure that all extra query parameters will be taken into account. An example of how you would do this: add_action( ‘pre_get_posts’, ‘wpse5477_pre_get_posts’ ); function wpse5477_pre_get_posts( $query … Read more

Find callback function for custom taxonomy metabox

The callback you need for non-hierarchical taxonomies is post_tags_meta_box. The callback you need for hierarchical taxonomies is post_categories_meta_box. For your example, the code would be: /* Remove movies metabox from sidepanel */ function hide_metabox(){ remove_meta_box( ‘tagsdiv-movies’, ‘your-post-type’ , ‘side’ ); } add_action( ‘admin_menu’ , ‘hide_metabox’ ); /* Add back movies metabox, but in post area … Read more

add_rewrite_rule and custom variable

Hi @westondeboer: Since you are saying your post type is ‘portfolio’ here’s what works on my WordPress v3.0.4 test site with a ‘portfolio’ custom post type defined. It replaces all the code you have: add_action(‘init’,’yoursite_init’); function yoursite_init() { global $wp,$wp_rewrite; $wp->add_query_var(‘view’); $wp_rewrite->add_rule(‘portfolio/([^/]+)/all’, ‘index.php?view=all&post_type=portfolio&name=$matches[1]’, ‘top’); // Once you get working, remove this next line $wp_rewrite->flush_rules(false); } … Read more

How to quickly switch custom post type singular template?

you can do it like this: //add movies_view to query vars add_filter(‘query_vars’, ‘my_query_vars’); function my_query_vars($vars) { // add movies_view to the valid list of variables $new_vars = array(‘movies_view’); $vars = $new_vars + $vars; return $vars; } then add a template redirect based on that query_var: add_action(“template_redirect”, ‘my_template_redirect’); // Template selection function my_template_redirect() { global $wp; … Read more