The primary loop query post ID is stored in $current
. This variable is equivalent to $post->ID
. The secondary loop query post ID is available within the loop as $post->ID
. Thus, you just need a simple if
statement in side your secondary loop:
<?php
if ( $current == $post->ID ) {
// This post is the same as the
// primary loop's current post;
// do something
}
?>
For example, to add a “current-article” class, I’d try the following on the <li>
<li<?php if ($post->ID == $current) echo 'class="current-article"'; ?>><!-- stuff here --></li>
Related Posts:
- Nested meta_query with multiple relation keys
- numberposts? showposts? posts_per_page?
- Is there a way to extend WP_query so Custom Post Types can have properties?
- How can I save an array from a random post sequence for later use?
- All-in-One Event Calendar: Custom Query – Getting each event Instance [closed]
- Is there an action/filter called when WP_Query->query is finished and assigns posts
- Calling a wp_query $posts causes a 500 error
- Limit search results to exact match
- Highlighting Sub topic in a post?
- Pagination Not working on Home Page with 2 Query
- Multiple keyword search
- Get number of comments after modifying comment query
- Show default content if custom WP_Query has no posts
- How to run query inside a class with namespace?
- Include Sticky Posts with Custom Query
- $wpdb->insert inserting two rows in database
- How do you Query posts with nothing in common?
- Create unique page without header.php for json feed
- WP_Query Variable inside Array
- Sub-loop / nested loops Best Practices
- How to loop for every result found in the_content() when using the search query?
- Is there any advantage of using default WordPress Search instead of creating a custom one?
- Order By table field comment_status in WordPress > 4.0
- Clean up WordPress code that repeats
- How to optimize multiple WP_Query() calls on one page?
- Query to get siblings and parent page
- Use Repository Pattern in WP theme
- How to list custom fields as headers and list all pages sharing that custom field under it?
- Cutom wp_query for geolocation search, pagination not working
- Excluding pages in WP_query using ACF
- Include data from custom table in WP_Query
- echo a specific meta_key queried through a custom post
- WP Group posts by year(desc) > month(desc) > date(asc)
- Assign custom parameter to each post in query
- How to order posts on each different category?
- Get specific ACF key and value from all posts – no access to DB
- Orderby two meta fields not working
- Custom wp_query – I’m getting ‘all’ post, not the specific post in the query
- meta_query with array as value with multiple arrays
- Adding pagination to sub-wp_query within a singular post page
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- How to make a query returning pages from multiple parents
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Where is this query?
- How to use wp query in my custom page without including header and footer in wordpress
- Custom order revolution sliders post base slides as inserted in Specific Posts List field
- WP Query for all events prior to current date
- How to extend WP_query to a specific table?
- Display the search results like the original pages
- Multi line of $wpdb->query just run 1 time and end the loop right after
- Add to search posts query array with post IDS which will appear first
- Woocomerce – Order products by float attribute in archive pages
- Multiple values in WP_Query : category__and
- Get specific value from variable to use in query
- How to set up pagination for a custom loop on a global template (author.php, tag.php, archive.php?)
- Custom query using WP_Query is not working
- Limit the number of posts from a specific category on index.php
- Get the type of an advanced custom field (ACF) in a WP_Query loop [closed]
- Switched from query_posts to wp_query, pagination no longer working
- WP_Query breaks pagination
- My class function is not seeing GET url paramaters
- Pagination problem with multiple loops on the same page
- shortcode with $atts with strange results
- I need to get all categories from a WP_Query
- meta_query ‘compare’ => ‘IN’ not working
- WP_Query and next_posts_link
- Sanitation needed for WP_Query or get_posts calls?
- replace the WP_Query class in the main query
- WP_Query hit max joins… How else can I build a search function that uses custom fields?
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Order terms inside a select dropdown
- WP_Query orderby breaks when using AJAX?
- Detect featured image among the attached images
- Pass arguments to WP_Query using “set” method
- Search Posts with Custom Fields as query
- Set order of returned items in the WP_Query() class/function
- Use query->set or make new query?
- Show Sticky Post at the top but do not show again in the loop?
- How to display multiple custom fields with the same meta_key in an ascending order?
- Using the_post_thumbnail resets current loop item ID
- Assign Json file to WP_Query
- Removing duplicate values between two wordpress queries
- Issue with front page navigation after upgrading to 3.4
- Ordering posts by an array
- WordPress Custom Search Form Displaying Unexpected Results
- WP_Query offset is returning post from prevois loop
- Does WP_Query ‘responds’ badly to empty arguments?
- Does putting queries within loops cause an issue on WordPress?
- Adding query parameter to archive page returns 404
- WordPress AJAX Request returns 400
- Using wpdb prepare with a variable, turns it into a big string
- SQL to join u3g_users & u3g_meta_value with repeating data
- Separate by Category Post Type
- ACF: using two loops, the_field returns field content from another loop
- Combine WP_Query with array of custom data to single loop without breaking the pagination
- Where can I find the declaration of `$_wp_theme_features`?
- WP_Query with Pagination and orderby meta_value_num showing duplicates
- Optimising specific Query with ACF meta objects
- Slow getting posts from category
- Pagination not working with WP_Query (creates links but no page)