Possible you’ve forgotten to reset post with wp_reset_postdata function.
You can use get_posts instead of new WP_Query:
<?php foreach(get_posts($args) as $post) : ?>
<div class="post">
<a class="post-link" href="https://wordpress.stackexchange.com/questions/277736/<?= get_permalink($post->ID) ?>" target="_blank"><?= $post->post_title; ?></a>
</div>
<?php endforeach; ?>
Related Posts:
- Inject post (from specific category) between posts in Loop
- Looking to exclude blog posts from category Previous/Next buttons
- How to display related posts from parent category
- Use template for posts with a particular category grandparent
- how do I get a specific post from a post with a subcategory in WP
- How to show only subcategories in parent category not parent category?
- Get latest post from all categories except one
- Add new post in existing categories using wp_insert_post
- Displaying list of posts in category page
- Do not duplicate posts with multiple categories in multiple loops
- Loading Posts & Category with Ajax
- Pagination at category doesnt work with same name of page
- How to show categories and date on posts
- Trying to show the category of a post in the post display
- Unable to get Post Category Name and URL
- Trying to see if page is category or single and displaying title with appropriate heading tag
- Display post of specific category on page
- Display current category title on category page
- Disable Attachment Pages Completely
- How to get year, month and hour in WordPress?
- Allow authors to post only in categories they create in WordPress
- List all categories but exclude current post category on single post page
- Handling an Ajax form submit
- Edit category output
- Print number of post (in reverse)
- Count number of published posts by type
- Different background-image by category
- Get taxonomy terms only of the WP_Query current posts
- How to get 2 or multiple custom post types in wordpress functions.php
- Displaying a button on each post
- Creating bulk posts with Youtube videos
- How Display Posts on category
- hover image appears below placeholder instead of overlayed
- get current product name in functions.php
- Getting a specific post values to another div or modal
- Display post category in foreach loop with category link
- Unreadable pagination
- How to exclude category ID from Looper in WordPress
- WP grandchild categories in nested ul li
- Get page that displays all children of taxonomy parent
- Open post-content in archive page in a Modal box with bootstrap
- Dilemma of Populating all the categories in a drop down list
- JSON REST API WordPress only showing first 10 categories
- Get all categories post is not in
- Parse error: syntax error, unexpected end of file
- Automatically add images to a menu
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- In WordPress, how do I get the number of posts next to single_cat_title(”); in the category.php file?
- Store metakey value as an array
- Only show first image in foreach loop
- Post not populating for custom post type based on category selection
- Removing sidebar on category pages
- show recent posts php code error?
- Post to WordPress from another Server via PHP
- form $_post action value gets truncated after it passes through two forms
- Wrap posts p tags in div
- How to display only one category in a custom post type?
- go to home page when i select default in select-box
- get value from get_post_meta then reuse it in another get_post_meta
- Wrong Number of Products When Hiding Subcategory Products From Showing In Parent Category
- Generating 10 000 WordPress posts using PHP and avoiding Server Timeout error
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- Filter wordpress posts without searching the keywords in the post content
- How do I edit the terms output args or array data?
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- How to Send Pingbacks for all Posts in WordPress?
- Display Visual Composer shortcode if a post belongs in specific categories
- Display articles with a different template in the home page | Solved |
- How to get post titles by post ID and integrate with my code?
- Infinite looping next post link within a certain category on a post
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- Hide a specific category title from displaying on site
- How to use a PHP file to control the content of a blog post
- Return to the beginning of the results of a for loop
- Exclude category and post from loop in custom category.php
- Admin backend, show post from a category and exclude the posts from subcategories
- Custom Post By Category
- Exclude a category slug on pagination
- How to Retrieve All Category Images on Front-End
- Displaying POST content with HTML tags and all
- Pagination in WP Queries
- Add div after every 4 posts then every 2 posts for a responsive loop
- get_category display only 1
- Can’t put a hyperlink on Featured Post’s Image
- WordPress get_post_meta issue
- Make an array listing custom taxonomy
- Get category id for a custom category and display it in a class
- Automatically create a loop for post ID
- Is there a way to randomize and connect a background and header image?
- Display pages from specific page template
- wp_get_archive for category returning different URLs on different but similar sites
- dynamically filter by category via sub-menu
- Older entries link within a category page
- Get unique post in parent category
- Incomplete term slugs output from a foreach loop with get_the_terms
- Query posts by custom fields (object post)
- How to display the date under the post title?
- Excerpt all post content Content Same Size without word cutting off
- Add multiple HTML attributes to an Elementor button
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false