Select posts wich has no relationship in custom taxonomy

I have found an answer by myself, for those landing here by google: $taxq = array( array( ‘taxonomy’ => ‘story_lng’, ‘field’ => ‘id’, ‘operator’ => ‘NOT EXISTS’, ) ); That results in AND (NOT EXISTS( SELECT 1 FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id WHERE wp_term_taxonomy.taxonomy = ‘story_lng’ AND wp_term_relationships.object_id = wp_posts.ID)) AND … Read more

Posts per Page on custom Taxonomy Template

number_posts is not a valid parameter in pre_get_posts, you should be using posts_per_page You should also include a check (!is_admin()) in your query to check whether you are on the front end or back end as pre_get_posts alters back end queries as well Rewrite your code to the following: add_action( ‘pre_get_posts’, function ( $query ) … Read more

How to pass posts_per_page and paged params query vars to custom taxonomy archive urls?

If I try to add &posts_per_page=15 to url, it doesn’t work: it won’t change number of post. I wonder if you’re looking for a custom query variable, e.g. ppp, to change the number of posts for the main query: add_filter( ‘query_vars’, function( $vars ) { $vars[] = “ppp”; return $vars; } ); add_action( ‘pre_get_posts’, function( … Read more

Hide child term posts on parent term pages

I think that the best solution is to hook into the pre_get_posts action hook. First, it is checked if we are in an archive of your custom taxonomy, then set include_children to false for the tax_query argument of the query. add_action( ‘pre_get_posts’, ‘cyb_pre_get_posts’ ); function cyb_pre_get_posts( $query ) { //Assuming the slug of the custom … Read more

WP_Query | Help me create a search term with an ‘OR’ relation?

(Revised on March 25 2020 UTC) So in this revised answer, I’ll just begin with the code: Define the variables: (I intentionally included only the $args part) // define POSTed/submitted variables here like $paged, $display_count and $direction // define the offset/’direction’ stuff here // then define your $args array $args = array( ‘post_type’ => ‘product’, … Read more

Custom permalinks – post type – hierarchical taxonomy’s

Thanks for referencing my solution. You forgot one part though – defining the rewrite of your cpt. From my solution: First get your slugs right when defining your custom post types and taxonomies: for the custom post type it should be basename/%taxonomy_name% and the slug for your taxonomy should be just basename. Dont forget to … Read more