For both loops move
<a href="https://wordpress.stackexchange.com/questions/67673/<?php the_permalink(); ?>">
To after
while ( $the_query->have_posts() ) : $the_query->the_post();
the_permalink()
is template tag and as such generates what it does, based on global $post
variable. In your custom loop it doesn’t contain the post you want until after $the_query->the_post()
call.
Related Posts:
- WP_Query condition affects posts_per_page count
- How to display an other custom post type in a different custom post type’s archive?
- When to use WP_query(), query_posts() and pre_get_posts
- Nested meta_query with multiple relation keys
- Query posts only with featured image
- WP_Query vs get_posts
- Using OR conditions in meta_query for query_posts argument
- Order posts by ID in the given order
- Query Multiple Post types each with own meta query
- Get posts by menu ID
- Get the number of posts from the current page results
- How to know which one is the main query?
- get query’s query string
- Meta Query with date and time on the same Day before given time
- In loop: posts have thumbnail AND other variables
- Determine WP_Query parameters from URL
- Multiple search queries on one page
- Get the post permalink within the loop but without additional DB query
- How do you query wordpress posts using a math formula between multiple meta field values?
- How add a custom posttype name using ACF field to a query post array
- Get image of latest post from taxonomies/categories
- Page navigation doesn’t show when query category
- 2 loops on page – one with orderby rand second orderby date
- Next/Prev posts on same page
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- How to query a custom post type with a taxonomy filter but display post type archive page?
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- Five posts from a category in footer
- WordPress add_rewrite_rule() cannot visit lower url levels
- Change query_posts to WP_Query in page but does not work
- How can I create ‘future’ and ‘past’ parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?
- Serve specific “template” page at any URL that ends in its slug
- How to display multiple custom fields with the same meta_key in an ascending order?
- new WP_Query(), have_posts() return false in user_register hook
- how to make members list directory through wordpress post custom meta key.
- Add class to first post in custom loop using post_class filter
- Some doubts about how the main query and the custom query works in this custom theme?
- Retrieve posts using thumbnail id as meta key
- How to exclude post formats from wordpress recent posts in a tabs widget [closed]
- How to increase load time of an archive/search page (WP_Query)
- Query Page Content From Theme Options?
- Query all posts if multiple meta key don’t exist
- How to get all post except particular category without breaking the paging
- How do I rewrite this loop as a new WP_Query style-loop?
- How can I check for a thumbnail in WordPress?
- Include current post into loop
- Filter Custom Taxonomy Posts
- How to display the featured image for each post?
- Query posts only without featured image
- Easy way to write complex queries in wordpress
- Filter post query to only show direct children of category
- Order post type by sum of two custom fields
- get_posts output always same post
- Query_posts works when appending via AJAX call wp_query doesn’t?
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Posts Query | Query to only show sub categories
- Loop posts based on permalink term
- How do I add a relation parameter to my filter query?
- Getting the permalink to the latest post from a category
- Get next/prev image/attachment in time with date query
- Show single posts date, in a page of posts
- specific post is not excluded from the loop
- Why doesn’t my WP Meta Query return any results?
- Paginate pages with dynamic query
- filter posts by meta key with pagination
- Trouble Making WP_Query paged
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Determine if ID is page or post and query the ID
- WP_Query Class custom field parameters
- Add AJAX “Load more” on custom query block
- Optimising WP_Query with ACF Fields
- Elementor posts custom query based on tag [closed]
- Filter products on category AND tag
- Facing problem with tax_query results
- Generate custom output on URL with directory
- How do I stop the same post showing multiple times in a archive?
- Get posts that match defined arrays of tags
- trying to change from query_post to WP_Query
- How to query most recent post for each author?
- I need query_posts() to order results first by a meta value and then by post ID
- WP_Query how to add a thumbnail to the first post from the last 5 posts?
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- How to search CPTs in draft using get_page_by_title()
- Orderby query does not work for custom fields even with meta query
- Custom WP_query and integrating into theme file
- query_posts() doesn’t seem to be called in my page
- Some doubts about how the main query and the custom query works in this custom theme?
- Fetching $_POST from Page Template into functions.php
- Ordering Posts by parent category, name ascending
- Optimising specific Query with ACF meta objects
- Featured image not showing on page
- How to organize a WP_Query’s list of posts by category and display category title?
- query_posts with sorting on a custom datestamp
- query post based on comparison
- Query Posts by date range with fixed beginning and end
- Multiple loop for “featured” items returns wrong posts
- Having trouble using this post category query on multiple pages?
- query_posts problem – need help
- The permalink redirecting to current article on single.php page