get_posts() seemingly ignoring post_type

I built a workaround for now, but would really love to know what is causing this. The workaround was obtained by removing changing “suppress_filters” to true and then adding a function that adds to the where clause of the SQL… But I would rather know how to fix this at the root rather than a … Read more

Want to filter only parent post in admin area

In addition to my previous answer add following code. It should work fine add_filter( ‘views_edit-books’, ‘add_filter_link’ ); function add_filter_link( array $views ) { $url = add_query_arg( array(‘bfilter’=>’parents’,’post_parent’=>0,’post_type’=>’books’), ‘edit.php’ ); $views[ ‘post_parent’ ] = sprintf( ‘<a href=”%1$s”%2$s>%3$s</a>’, esc_url( $url ), ( is_filter_active() ) ? ‘ class=”current” aria-current=”page”‘ : ”, ‘Post Parents’ ); return $views; } function … Read more

WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)

Nevermind I (think) I got it… $args = array( ‘post_type’ => ‘product’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array( ‘ring’ ), ), array( ‘taxonomy’ => ‘product_tag’, ‘field’ => ‘slug’, ‘terms’ => array( ‘black’, ‘men’ ), ‘operator’ => ‘AND’ ), ), ); Missing the ‘operator’ => ‘AND’ … Read more

Transient pagination not working properly

Short answer: You are making the same query no matter what page you are, but you’re expecting a different result. Long answer: The query should be different for second page, having paged=2, so your query (and transients) with pagination should look like this: $paged_var = get_query_var( ‘paged’ ) ? get_query_var( ‘paged’ ) : 1; if … Read more

prevent showing posts of an specific category in admin posts section

You can use the pre_get_posts action to affect any queries, both in frontend and admin. In your case you should make sure you affect only admin queries and you can even use get_current_screen to narrow it down further. Here’s an example that would modify the query only on the regular posts page: add_action (‘pre_get_posts’, ‘wpse311946_restrict_cats’); … Read more