WP_Query outputs wrong post in custom post type

This has been solved. add_action(‘admin_head’, ‘set_scheduled_today_tag’, 99); function set_scheduled_today_tag() { global $post; $args = [ ‘post_type’ => ‘wp_events’, ‘post_status’ => ‘any’, ‘numberposts’ => -1 ]; $posts = get_posts($args); if ($posts) { foreach ($posts as $post) { setup_postdata($post); $post_date = get_the_date(‘Y/m/d’, get_the_ID()); date_default_timezone_set(‘America/Chicago’); $current_date = date(‘Y/m/d’); if ($post_date === $current_date) { wp_set_object_terms(get_the_ID(), ‘today’, ‘event_tag’, true); } … Read more

Passing in MySQL prepare statement parameter separately throwing error

$query = (“SELECT * FROM <tablename> WHERE user_id = {$user_ID}”); // string variable $stmt = $wpdb->prepare($query); Say your $user_ID is 9, this will get evaluated to: $query = (“SELECT * FROM <tablename> WHERE user_id = 9”); $stmt = $wpdb->prepare($query); and finally becomes $stmt = $wpdb->prepare(“SELECT * FROM <tablename> WHERE user_id = 9”); Now it is … Read more

ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)

This isn’t possible using WP_Query, you can’t query the insides of structured data stored in a single post meta value. At best you can use regular expressions, or do math/boolean comparisons, you can even do LIKE comparisons, but these are all string operations. If you need to query structured data such as objects or arrays, … Read more

WP_Query order by multiple meta keys & fields

You are using meta query without setting a value. The way you are doing it is using to query posts, not to order them. Using Named Meta Queries To order your posts by different meta datas, you can give your meta queries a name and then use that to set the ordering. Here is a … Read more