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
- Passing a variable containing a comma separated list of values in a meta-query
- $wp_query->found_posts; returns zero
- Rewrite URL custom search query
- How to remove “MY WORDPRESS”” Label
- How could i add username field in WooCommerce
- Query post with meta value in set of values
- get_template_part causes 500 error
- WP_Query args to show posts from specific custom taxonomy
- WP_Query for a taxonomy with different taxonomy types
- How to query woocommerce product by pricing? [closed]
- Finding WordPress Posts assigned to multiple categories
- WP Query – order posts by meta field first and then order the rest
- ACF Query Structure
- Reusing content from front page on sub page
- The most effective way to split by post type in custom query?
- Append URL query to next post link in custom query
- Get Child Page IDs by Parent ID
- How to compare a date in custom field with today’s date in custom WP_Query?
- Customy WP Query Args are convertet in SQL result
- Meta Query doesn’t works as espected
- Can I modify a WP_Query instance or clone it with modifications?
- Can’t sort custom post type by random
- Ordering posts by an array
- Include posts from some categories while excluding from others
- Include post content of linked posts in search
- how would i change post->ID to work correctly when querying pages?
- pre_get_posts – Trying to get property of non-object warning
- Replacing search results with custom external query
- Prevent author bio page from showing in search results
- WP_Query gives me different results depending on the category order
- WP User Query with Custom Fields and Search Results
- Make a SQL query with wpdb in WordPress
- Exclude parent with child pages from WP_Query
- Co-authors list of all posts
- Changing the default wp_search_stopwords
- post_type argument not working correctly with WP_Query