Filter all queries with a specific taxonomy

Below code is an example that does what you want. See tax_query for more information. function my_get_posts( $query ) { // we only need to modify the query for logged in users if ( !is_user_logged_in() ) return $query; $current_user = wp_get_current_user(); // assuming that user’s region is stored as user_region meta key $user_region = get_user_meta( … Read more

Custom search for custom post type, custom meta and search fields

If you want to extend your query, you should extend it through the pre_get_posts-filter. Then just do a “Custom Field” or meta query. add_action( ‘pre_get_posts’, ‘wpse105969_extended_search’ ); function wpse105969_extended_search( $query ) { // Make sure we got a search query // and we’re only modifying the main query. if ( ! $query->is_main_query() AND ” === … Read more

Order posts by (hierarchical custom) taxonomy terms and term children

This query will handle two levels of hierarchy in your taxonomy. More than two levels of hierarchy and you’ll need a recursive self-join. What this does is return the posts in the correct child within parent order. To create the appropriate parent level headings, you’ll have compare the current post’s parent taxon with that of … Read more

How can I display parent and child taxonomies in separate drop downs?

Hello Everyone out there, who are facing difficulty to display the parent and child taxonomies in drop down, i found the solution for the above problem…… edit the code in the functions.php file, before the code was $categories= get_categories(‘child_of=”.$_POST[“main_catid’].’hide_empty=0′); now edit the code, like this… $categories= get_categories(‘child_of=”.$_POST[“main_catid’].’&hide_empty=0′.’&taxonomy=state’); and this works so beautifully, try it for … Read more

Categories under custom post types doesn’t show properly

Categories and Taxonomies are not exactly the same. A category is a default taxonomy You can use categories with custom post types however its better to use custom taxonomies because the truth is, they are an extremely powerful way to group various items in all sorts of ways. add_action( ‘init’, ‘wpsites_custom_taxonomy_types’ ); function wpsites_custom_taxonomy_types() { … Read more