Articles of wp query

How can I combine meta_query queries?

I’m trying to build combined meta_query queries but they don’t work. Any ideas how I can implement queries like the example below? Thanks, Hinnerk Array ( [relation] => AND [0] => Array ( [key] => price [value] => 1000 [type] => numeric [compare] => <= ) [1] => Array ( [relation] => OR [0] => […]

Pull post meta with post_query?

I’m building a custom index loop that just uses query_posts at the moment. The issue is that inside The Loop, I have to then query for the post meta data (with get_post_meta), which I believe has to query the DB each time it’s called. Is there any way I can pull the meta data with […]

Best Practice For Querying Grandchildren?

Objective: Query and loop through a page’s third-level “grandchildren” in a way that allows pagination. Here’s the code that I’m using (pagination excluded): // Get the ID of the first generation $gen1_ids = $post->ID; // Query for second generation IDs $gen2 = $wpdb->get_col( “SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen1_ids) AND $wpdb->posts.post_type = ‘page’ […]

Prevent duplicate post from dynamic multiple loops

I was trying to list 20 recent posts, and put a post from custom post type on every 5th item. So it’s like: Post Post Post Post Post Custom Post Type Post Post Post Post Post Custom Post Type .. and so on. Here’s what I did so far. It’s working but the custom post […]

How WordPress attaches its Featured Images with posts?

I’m working on a WP_Query(), where I’m trying to fetch all the images using ‘post_type’ => attachment and ‘post_parent_in’ => array( 1688 )(I want to pass some more post_ids) along with other parameters. With these I can fetch all the attachments, but the featured image. I attached two different images into a post to check […]

Remove duplicated values from a loop

I have a loop that outputs <option> fields for a <select> group. It contains many cities’ names for many travel packs that I am publishing. The trick is that I need avoid repeated values. For instance: I have 4 travel packs departing from Chicago, 5 from Orlando, 3 from Los Angeles e 2 from New […]

Display posts if specific country

I’m running a simple query that displays some posts within a custom post type. Via each post within that post type, I’ve added an ACF True / False checkbox. If the checkbox is ticked, I’d like that post to only appear if you’re within the USA. Here’s what I have so far: <?php // Begin […]

current_post not working – give me -1 for every post

I try to get the current post index number and echo the number of this lesson(post)in a series of lessons(category). I’m inside the loop on single.php page my code looks like this: $args = array( ‘cat’ => 22, ); $query = new WP_Query( $args ); echo $query->current_post; echo $query->post_count; the “$query->post_count” works great and give […]

Splice together 2 WP_Query objects

I have been trying for a few days to make a homepage that displays all my posts, and after every 2 posts, a testimonial. I have found dozens of articles describing how to count while you are in the loop and place something every ‘n’ number of times. Thats no problem, but what is a […]

How to get to a specific position in wp_query?

Background: I’m trying to display images in a slideshow, and I want to select those pictures randomly from the website’s media. The image has a custom field in order to be selected for being the slideshow. I was able to figure all of that out, and I used a wp_query to find all of the […]