Sort wp_query of two post types using meta datefield for one and date for the other – possible?

Try this WP_Query arguments: $args = array( ‘post__in’ => $all_ids, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘_event_date’, ‘compare’ => ‘EXISTS’, ), array( ‘key’ => ‘_event_date’, ‘compare’ => ‘NOT EXISTS’, ‘value’ => ‘dummy_value’ // This is just to ensure this condition gets evaluated. ) ), ‘orderby’ => array( ‘meta_value_num’ => ‘DESC’, ‘date’ => … Read more

Group users by meta field, with name of meta field as group title

i need to return/echo the name of the department/location for each group of employees That is actually a generic PHP/programming question, nonetheless, if you mean an output which looks like so: Location/Department Name – Employee/user – Employee/user – Employee/user Location/Department Name – Employee/user – Employee/user Then here’s one way of accomplishing that: Add this above/before … Read more

Removing filename searches when searching attachments

Approaching this from the SQL is a mistake, and instead a quick search of the official dev docs for filename reveals a filter named wp_allow_query_attachment_by_filename that is set to true by default: apply_filters( ‘wp_allow_query_attachment_by_filename’, bool $allow_query_attachment_by_filename ) Filters whether an attachment query should include filenames or not. This means you can disable querying filenames … Read more

How WP determines archive page vs single page?

TL;DR: WordPress uses URL query string variables to select a template based on the Template Hierarchy. General template selection steps Permalink structures are used to create rewrite rules. Rewrite rules take a pretty permalink URL and convert it into a plain URL with a query string. Parameters from the query string are used to choose … Read more

Passing a variable containing a comma separated list of values in a meta-query

In WordPress meta queries, when using the ‘compare’ => ‘IN’ comparison, the value should be an array, not a string. When you manually input array( ‘1302’, ‘1329’ ), it works because it’s correctly formatted as an array. However, when using $artists_string_value, it’s treated as a single string, not an array of values. You should modify … Read more

SQL command to delete bulk WP post specific

Deleting posts directly in the DB is not going to clear up all their comments, post metadata, etc. I’d recommend using wp_delete_post() to do this instead. // Gets the post IDs. $author_id = get_user_by( ‘login’, ‘newsagencies’ ); // Use the user’s login here. $posts = new WP_Query( array( ‘author’ => $author_id, ‘date_query’ => array( ‘after’ … Read more

Unexpected number of loops in while

This is because have_posts() is for the main loop, and not your custom query. Prefixing each use of have_posts() and the_post() with $WatchListQuery-> will fix it: if ( $WatchListQuery->have_posts() ) { while ( $WatchListQuery->have_posts() : $WatchListQuery->the_post();