Articles of wp query

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 […]

Display List Of Posts Containing a Relationship Field Value

I have a post type called ‘Writers’ and another post type called ‘Documents’. I use the Relationship field in Advanced Custom Fields to link a list of Writers (post objects) to a Document. This means that the field is basically an array containing multiple writers (some contain only one). I have a template in my […]

if/else on custom query gives 200 OK when condition not met?

What? I am modifying my theme to show comments of a post on a separate page. How? Mostly based on this answer but with improved checks and code. So this is what my page-comments.php (kinda) looks like: (The code is very easy to scan through, trust me!) <?php get_header(); ?> <?php /* * (Example URL: […]

Get list of posts which have at least one term from a custom taxonomy with WP_Query

Is it possible, with WP_Query, to get all posts which have at least one category or custom taxonomy term set?

WP_Query arguments to fetch custom post type posts which are in certain category?

I’ve played around for hours but still can’t wrap my head around the right arguments for a secondary WP_Query which shall fetch all posts of my_custom_post_type that are in the queried category. Scenario is a custom category.php template file (writing a custom theme) to render a category archive for custom post type posts. Hence, the […]

How to add custom query filters in WP_User_Query

I am creating a list of all users in wordpress. For that I am using WP_User_Query with meta_query so that I can show only filtered users. I am stuck where I want to add a custom query filters in SELECT p.distance_unit * DEGREES(ACOS(COS(RADIANS(p.latpoint)) * COS(RADIANS(mt30.meta_value )) * COS(RADIANS(p.longpoint) – RADIANS(mt31.meta_value)) + SIN(RADIANS(p.latpoint)) * SIN(RADIANS(mt30.meta_value)))) AS […]