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]
- Get the ID of the latest post
- How do you get the count of posts in an archive page?
- tag.php doesn’t work with tags on a custom post type post?
- Assign single template to multiple custom post types?
- Add Content to Page without shortcodes
- Custom taxonomy query for a custom post type
- ascending order custom post type
- Display posts of child category in template
- custom taxonomy – Template not working
- How do I provide a “show all posts” link in a paginated term archive?
- How to list custom post types?
- List custom post type by custom tax term as page title
- Unable to get post content from custom post type loop
- Pass the_post() as a parameter
- Plugin templates in which directory
- get_template_part and template file names
- Using wordpress template tags within an array
- Creating select dropdown with parent-level custom post types
- How to query_post custom posts within default taxonomy?
- Custom Theme With Custom Loops
- How to make WP_Query not to show irrelevant posts?
- What is the ID parameter for custom post types in query_posts?
- Custom posts template page
- the_post() is printing titles in page footer
- Two column layout with alphabetical ordering
- Add Previous/Next Buttons to CPT Single Pages Only
- Dynamically insert code to custom post type loop
- Pull in taxonomy field of custom post type in new query
- How to add a lightbox to class mix?
- Apply template by path/slug related to custom post type?
- Posts are not rendering perfectly [closed]
- List all posts in taxonomy term
- WP not recognizing custom post type / template
- Looping through custom taxonomy and display custom post types (Custom Post Type UI)
- Custom post class, generate unique id from 1 to x depending on amount of posts?
- Get post-meta value of all custom-posts – lowest to highest year-count?
- One Custom Post Type two different Templates
- Query all posts under one taxonomy? Why is my code not working?
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- creating a foreign key like relationship with custom post types
- How to Enable Ascending or Descending In WordPress Default Built-in Loop
- Fetch data from two custom post types and create multidimensional array for output to html table
- Loop all post on single.php
- Pin posts to top of custom loop
- Post template with breadcrumb needs to show page navigated from
- Combine multiple separate lists into one
- custom post type single page
- WordPress Custom Post Type – Post Attribute: Template. Template shows up and saves on the back end, but the default theme file is being rendered
- Custom post types not displaying per category
- Custom post type with two templates
- Custom Post Type tag taxonomy “Page Not Found”
- How to show Y number of custom posts after every X normal posts?
- DIVs not showing correctly on CPT?
- Query Distinct Taxonomies of Custom Post Type
- How to loop custom post type posts by author?
- Inserting random posts
- loop through custom post-type with two meta_keys
- Loop to pull content from parent element in custom post type [duplicate]
- Inserting two categories