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 could i add username field in WooCommerce
- Orderby ASC changes to DESC in WP_Query
- How to query custom post types with mixed AND & OR statements for custom fields
- Error with function in functions.php?
- I am having problem sorting custom post type using WP_Query
- difference between querying database and using the loop
- How to do logical OR in terms in WP Query?
- Error in meta_query not get result
- How to sort wordpress posts already selected by WP_QUERY
- Merge wp-query and get_users
- get last child post by wp_query
- WP Query get posts by specific author IDs if one of several logged in authors
- How to get all post_id and meta_value using meta_key in wp_postmeta table
- List categories using WP_Query
- WP Query – Show custom posts only if user contain some user meta
- How do I subquery with custom meta fields?
- Show number of posts AND number on current page (cannot make it work)
- How can I get taxonomy term name using term slug & post ID using build in WordPress function or class?
- Why does wp_query only display the most recent post when using order ASC?
- Advanced Search – Is this possible?
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- AJAX multiple search boxes not merging with array merge
- Display Featured image from custom post type category (custom taxonomy) wise
- new WP_Query with order args – no more distinction between categories
- How to make OR condition in WP_Query
- Why WP_Query with the same arguments retrieves different results?
- When I visit my website there is only slash(-) showing intead of home or my website name. how to solve this? I am attaching image also to understand
- How to get products with the same custom attribute like ean code
- When to use WP_query(), query_posts() and pre_get_posts
- query loop “inherit query from template” prevents setting sort order
- Using a Query Loop Block with Variables (Custom Meta)
- has_term not returning anything