1st query:
$exclude_post_top_stories="";
// WP_Query arguments
$args = array (
'post_status' => array( 'publish' ),
'posts_per_page' => '-1',
'order' => 'DESC',
'orderby' => 'date',
);
// The Query
$exclude_query = new WP_Query( $args );
// The Loop
if ( $exclude_query->have_posts() ) {
while ( $exclude_query->have_posts() ) {
$exclude_query->the_post();
// do something
$exclude_post_top_stories[] = get_the_id();
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
2nd query:
$args = array(
'posts_per_page' => 2,
'post_not_in' => $exclude_post_top_stories,
'post_type' => 'post',
'post_id' => $post_id,
'category_name' => 'News
);
Related Posts:
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Get current post id in functions.php
- get_post_custom stripping styling issue
- get post id in while loops outputting page id
- How to get Advanced Custom Field Value According using POST ID? [closed]
- Automatic value for custom fields for posts
- Guest Author – How to display posts on /author/ archive page
- WP_Query orderby not working with meta_value_num and menu_order
- How can I sort posts by the date and a custom meta field?
- Query Posts With Over 1000 Views
- Query Posts by Custom Field
- Redirect to another page using contact form 7? [closed]
- How to I retrieve the ID from the Posts page?
- Saving Post Data in Another Database
- How to display post list in a table layout (multiple queries in single loop)
- If custom field is empty, use one from a previous post
- Override WordPress core post-template.php block template
- Query on a repeater date (acf)
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- WP_Query sort by meta_value_num or date
- Creating Ordered Query using Meta_key
- Auto populate custom fields by post date
- ACF Relationship – Get Parent’s Post Object
- WP Query between posts custom fields [duplicate]
- Using Post ID and Page ID in same function
- Order posts by separate menu order for different sub-categories
- How do I show the post title if an advanced custom field hasn’t been used?
- How to make a local “scroll to ID” on post?
- How to detect if an ACF custom-field is really in use?
- Image inside the content is replaced with featured image from my older post
- Adding an option to post editor to show a site disclaimer or message
- Display/Filter post using if else statement
- How to sort WP_Post Object array by object field in php?
- Search results for ACF data
- Multisite how to display merged posts from two sites and sort by latest date?
- Saving canvas generated image when saving post causes 404 error
- Reuse old post ID for new post after deleting post
- Query prints posts without specific categories
- Filter posts by their related field’s custom field
- Display specific posts based on an ID of another post
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- Template with ACF and Pagebuilder
- Order by meta_key field in WordPress not meta_value field value
- a WordPress connected to 2 database
- How to display particular set of wordpress post on a webpage?
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- query posts with selected post ids first
- Get post attachment with post id
- Change URL of previous posts and next posts link in WordPress
- How to invoke a HTML custom button based on a HTML dropdownlist menu
- How to create page with post content in it?
- Order posts inside bootstrap card columns
- WP_Query, ACF field and array
- long-title posts do not want published
- How to remove a post from results by ID after query?
- Using a meta_value or postdate to to query and orderby
- Exclude posts in home slider from sections
- Is there a way to save different data when USER interacts with the same POST?
- How do you update post date (year only) in a separate custom field?
- Mix post date with post meta value using WP_Query
- Change post value in WordPress
- How to use two query result together in one loop
- show loop id post , only first id can read
- WP_Query that targets all categories
- Counting Posts by Category
- Fill the exclude array() in get_posts()
- show image gallery in archives or category page
- Assign a day of the week to post, e.g: Assign Monday to post and have it only appear when the day is Monday
- Page with Category Returning 1
- The first post appears twice
- filter posts based on menu_order
- Show 5 posts and than 3 posts offset with pagination
- Double loop output
- Change archive results based on GET request
- wp_query args with relation
- Ajaxify Post Sort
- How do I display posts ordered by a date custom field?
- Override wp_link_pages pagebreak with filter
- Get 5 most recent categories
- How can i take all ids from untrash_post action?
- Loop through all posts showing duplicates
- WP_Query extended with AJAX
- Manipulate query to show specific post
- How do I apply a wordpress function to something with no ID inside an archive page?
- Wp_query loop is not working as it should
- Get current user, change users post status to published
- Show all posts from the tags without having to set all of them
- Is it possible to query a category with specified posts?
- WordPress text field in array problem
- Displaying a specific sub-category’s posts from wp_query
- Random order of the 5 most popular posts
- Get from the dashboard the ID of the current post being edited
- Only get post_id [duplicate]
- My custom query is displaying random posts in random order
- Wrap group of wp query posts to parent div by date/year
- Is there a global page/post/product/anything ID?
- WordPress Request Post All Post ID in a Loop? [closed]
- Custom layout manager for posts
- Get query result according to merged array
- Surrogate ID for posts, is there an alternative field in the posts table?