So you have two loops : the main loop and the second one using $query
.
You want to compare if at some point of your second loop there’s a match between current post (inside the loop) and the processed post inside the $query
loop.
Am I right ?
Instead of checking permalinks I would propose to check IDs.
So on the first loop you create a variable with the current post id :
$current_post_id = $post->ID;
and in your second loop you just compare :
if($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
if( $current_post_id === $post->ID ) {
echo $post->ID;
} else {
echo "not found";
}
endwhile; wp_reset_postdata(); endif;
Not sure that is what you’re looking for, let us know.
PS: I should add to use a more specific name for your query, just to avoid name collision from a plugin or anything, like $my_prefix_query
Related Posts:
- Retrieving 3 latest post from each of 5 different custom post types
- How to query custom posts using a dynamic category
- Posts in Multiple Columns and Rows with one single loop
- Custom post type loops with different page templates
- Query for posts in 2 taxonomies
- ‘category__and’ for custom taxonomy?
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- How to dynamically build a multiple taxonomy query loop within a post type’s single loop?
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- How to insert content from another Custom Post type into Post?
- Change or update WordPress loop based on dropdown selection
- Show a Category X’s custom post type on Category X archive page?
- Listing all term items alphabetically / sorting loop
- pagination not working for category.php (custom post types in categories)
- Main query not querying any posts in custom taxonomy template
- 3 random images from custom post type, each in a div with a diffrent class
- Control content before and after custom post type loop
- Pagination not working on custom query on a page
- Loop through posts of only 2 statuses
- assign different templates to custom post type with homepage loop
- Assign a template to a custom post type when displayed by the main loop on the home page
- postsperpage value not being applied
- Query all post types but limit to parents
- Create a custom taxonomy template that loops through child categories in term order?
- Display Posts Query with IF function
- Custom Post type showing up in loop, regular posts are not showing up
- Custom Post Type Query W/Category Dropdown
- Custom Post Types Not Showing Up In query_posts Result
- On click some element i want to use some template
- Accessing download link from the loop with WP Download Manager Pro
- Can I show some specific post rather than latest post?
- Custom taxonomy template for custom fields loop [closed]
- get_permalink() of page the enclosing page not posts
- display news with pictures 3 small and one large (loop)
- Load different template for CPT (in loop) in my plugin?
- How can I pull information from my loop and divide them seperately?
- How do I correctly query posts from a post ID?
- How to exclude certain portfolios from a loop
- Render a loop in Timber (twig for WordPress)
- How to create custom page templates with default page layout framework?
- show custom post’s post in two different divs [duplicate]
- Display all taxonomy terms, add class if term applies to current post
- Return the latest post from a custom Taxonomy and Post Type
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Group CPT posts by custom taxonomy
- Custom taxonomy and custom post type – wrong permalinks and template
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Best way to style first post differently?
- Can I override a CPT template on a per post basis with Gutenberg block editor?
- A to Z List of Custom Post Type in three columns
- Custom post type, organized by categories
- What’s the WP way to load remaining custom posts?
- WP Query with categories only shows one post and ignores the category
- What to and how to proceed with CPT to make DB small and efficient?
- Content vs Template on custom post
- Polylang non-default language ignores tags in WP_Query
- How to edit this code to get the categories in achieve page?
- Category with post type pagination returns 404
- Post ID randomly printing on page
- A custom post within a custom post
- How to use custom template files in deeper directory?
- Display Custom Taxonomy Alphabetically
- Full Custom Post Type List Organised by two Taxonomies
- Displaying Custom Posts on a Page
- WordPress Doesn’t Generate Taxonomy Archive
- Shortcode not working with post counter
- A case for Hierarchical Custom Posts
- Problem: wp_query outputs all images on site
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- Get custom post type’s fields in a while loop as variables
- Custom taxonomy returns 404
- Custom Post Type within the Loop on Homepage (Page Template)
- The loop seems stuck to a single (now deleted) post
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Query posts based on the meta key values of logged-in users?
- Posts per row on archive page (custom post type)
- Filter widget outputs
- Adding Page Templates to post but it ignored it
- How do I know the ‘meta_key’ for ordering my custom post type
- Template for all categories of a custom post type?
- Limit the post for differents custom post type in the same wp_query
- Custom Theme With Custom Loops
- Custom Post Types strange pagination problem
- Different Ways to Query Custom Post Types?
- Migrating a taxonomy’s tags to the native category
- Flush Rewrite Rules when new site is created on network
- BBPress Search results in WordPress search
- Custom post type archive page for multiple post types
- Custom post type conditional in loop
- WordPress custom taxonomy template not working
- Display related custom taxonomy posts in sidebar
- How can I get this request to use the Custom Post Type page template instead?
- Only show posts with date of today or in the future (i.e don’t show past posts)?
- How do I control the output of a custom post type in the loop?
- How to display Related Posts based on number of taxonomy terms matched
- Display custom post type posts first, then default posts
- Custom Post Type Category Link
- How to specify a template for a path like http://example.com/something?
- Custom Post type category pages template and loop
- Custom templates for a specific category