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: https://developer.wordpress.org/reference/hooks/wp_allow_query_attachment_by_filename/ 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

WP Query filtering by custom category not showing all relevant posts

@jacob-peattie answered the question in his comment – I used the wrong key to set the number of posts my query generates. Swapping numberposts with posts_per_page solved the issue. Here’s the final query: @php $cats = get_sub_field(‘reviews_category’); // gets the custom field categories $args = array( ‘post_type’ => ‘testimonials’, ‘posts_per_page’ => -1, // this line … 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

WP_Query not using relation key as expected and not producing any results

From the developer docs: relation (string) – The logical relationship between each inner meta_query array when there is more than one. Possible values are ‘AND’, ‘OR’. Do not use with a single inner meta_query array. (Emphasis mine). It’s a bit hacky, but you could run a separate query against the meta field, then merge the … 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();

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)