Sorting by Title for Post Archive Categories for Custom Post Type
Sorting by Title for Post Archive Categories for Custom Post Type
Sorting by Title for Post Archive Categories for Custom Post Type
How to exclude first 2 posts from a specific category for a custom post type archive page
You could try modifying the tax query to use the relation parameter and add a second clause that matches any post that does not have the matched string value in the meta array. See Taxonomy Parameters. EDIT: Thank you for pointing that out, Tom. You’re correct, I’ve updated to reflect. function group_matched_posts_at_top( $query ) { … Read more
pre_get_posts is an action hook used for modifying the arguments passed to the WP_Query class, and if you’re filtering the posts in the list table at wp-admin/edit.php, then yes, you would use that hook. However, since you’re filtering the terms in the list table at wp-admin/edit-tags.php, then the hook that you should have used is … Read more
pre_get_posts has php notice when not on CPT archive
You can add a filter on posts_clauses to; left join additional columns for each meta filter add order by clause base on those column values. Something like below should work, assuming your meta key is start_date and the value has the actual date format Y-m-d and your post type is talks add_filter( ‘posts_clauses’, function ($clauses, … Read more
Search query alteration not working for meta values
For those running into issues in the future, this is what I did: I made my pre_get_posts function that queries the taxonomy as normal for testing if an taxonomy ID is not in a list: $q->set( ‘tax_query’, array(array( ‘taxonomy’ => ‘tax’, ‘field’ => ‘id’, ‘terms’ => tax_get_inactive(), ‘operator’ => ‘NOT IN’ ))); Then, I implemented … Read more
$qry->is_main_query() will be true on every main query on your site, front end and admin. You need to add another more specific condition to target only the page you’re trying to modify the query on, like is_post_type_archive(‘trucks’).
Awesome. This works! Thanks @Milo /*Change results based on the current user’s role and status */ function posts_for_current_role($query) { global $pagenow; if( ‘edit.php’ != $pagenow || !$query->is_admin ) return $query; if( current_user_can(‘editor’)): //Add query where clause to status equals “working”. $query->set( ‘post_status’, array( ‘working’, ‘draft’ ) ); endif; if( current_user_can(‘administrator’)): $query->set( ‘post_status’, array( ‘published’) ); … Read more