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 should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- Get post ids from WP_Query?
- Nested meta_query with multiple relation keys
- Some doubts about how the main query and the custom query works in this custom theme?
- Query posts only with featured image
- Wp get all the sub pages of the parent using wp query
- How to query for most viewed posts and show top 5
- WP Query where title begins with a specific letter
- WP_Query vs get_posts
- Search custom taxonomy term by name
- Using OR conditions in meta_query for query_posts argument
- Query Posts in a Predefined Order
- 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
- WordPress Custom Query to show posts from last x years
- Query Custom Meta Value with Increment
- How to know which one is the main query?
- Get posts by meta data OR title
- Perform query with meta_value date
- Using is_main_query to select custom post type on certain page
- WP_Query ordered by custom field that is a date string?
- 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
- get_the_title($postID) OR get_the_title()?
- Display Posts by modifying the where clause only for my query
- How do I create my own nested meta_query using posts_where / posts_join?
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- Best practice for multiple queries on page
- How to Get All Posts but the Private ones?
- How to query ‘posts_per_page’ to display a different blog posts index template?
- How to find out what “Blog pages show at most” is set to [duplicate]
- Determine WP_Query parameters from URL
- post thumb nail
- Multiple search queries on one page
- Trying to check and see if a post has a featured image outside of the main loop
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- Pass the same object to multiple widgets in a template with one query
- Get the post permalink within the loop but without additional DB query
- Retrieve or Query Pages by ID
- Query sticky posts with thumbnails
- Retrieve featured image (thumbnail) url from multiple posts with one query
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- 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
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Too many posts cause slow load when paginating
- Get image of latest post from taxonomies/categories
- Page navigation doesn’t show when query category
- post thumbnail not showing up with shortcode
- How can I pick a single post from the latest 3?
- 2 loops on page – one with orderby rand second orderby date
- How do you Query posts with nothing in common?
- Query post with meta_query where date is not in future
- Next/Prev posts on same page
- How WordPress attaches its Featured Images with posts?
- Custom category search box for WordPress
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- Query with custom taxonomy not working
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Query posts by specific word on title
- How to query a custom post type with a taxonomy filter but display post type archive page?
- WP_Query last five posts, simply ordered by meta_value
- Query with a meta value inside a given range
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- WP_Query “OR”: Find posts by ID, Name or Post Title?
- getting post thumbnail within loop causes an error
- Store sticky post’s ids in a transient
- Five posts from a category in footer
- How to build a WP_Query using mulitple tags and using AND or OR operator between them
- WordPress add_rewrite_rule() cannot visit lower url levels
- Change query_posts to WP_Query in page but does not work
- Multiple loops without repeating content
- Site not getting correct featured image from my query
- Custom Query num_rows returns wrong amount
- 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
- Fetch Record based on meta key dates
- 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
- add active class based on permalink and url
- Bypass “supress_filters” in WP Query
- Slow page loads due to WordPress Core Query
- how to make members list directory through wordpress post custom meta key.
- Add class to first post in custom loop using post_class filter
- Filtering out child category posts from parent category archive not working
- Some doubts about how the main query and the custom query works in this custom theme?
- Retrieve posts using thumbnail id as meta key
- Display custom tags on pages that have a specific page parent
- How to exclude post formats from wordpress recent posts in a tabs widget [closed]
- How to get list of posts from permalinks?
- WP Query – Post Thumbnail
- How to increase load time of an archive/search page (WP_Query)
- WP_Query Attachment adds additional attachment count and need to link attachment to post url