author.php with ACF and CPTs

REWORKED APPROACH The issue with the original answer is that although we pass post ID’s to post__in parameter, being on the author page, the main query removes all posts that does not belong to the author. We can pass an empty string to author_name via the pre_get_posts filter, but that inherintly breaks the query object, … Read more

Query all posts where meta value is empty

I think you forgot about the inherit post status. The default one in WP_Query is publish. You should also use = instead of LIKE, to avoid using LIKE ‘%%’ in the SQL query. So try to add this: ‘post_status’ => ‘inherit’ and ‘compare’ => ‘=’ into your query arguments, to match the empty _wp_attachment_image_alt string … Read more

Filtering a WP Query result

I solved my problem re-reading ACF’s custom fields documentation. Instead of meta_query, I should’ve used meta_key. The correct argument for a custom field is: // args $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘event’, ‘meta_key’ => ‘location’, ‘meta_value’ => ‘Melbourne’ );

Merging multiple wp_query objects

If you just need the posts of each WP_Query object, you can do do something like this: <?php // fetch blogs here $all_posts = array() foreach($blogs as $b) { switch_to_blog($b->blog_id); $query = new WP_Query(/* your args here */); if($query->have_posts()) $all_posts = array_merge($all_posts, $query->posts); // posts are stored in the `posts` property restore_current_blog(); // FYI: this … Read more

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