Ad
Multiple Post Types But Set The Offset Only For One
I am displaying multiple post types but i want to set a offset for one of those post type but how can i do that?
$args = array(
'post_type' => array('wins', 'memes'),
'posts_per_page' => '5',
//'offset' => '1', (with this i set the offset for both but i only want to set it for one of them.)
'post_status' => 'publish'
);
Ad
Answer
You could gather the IDs that you do not want. If you don't have a specific order needed from the post type with the offset, and are just looking for the 5 most recents posts from that type. You can do the following:
<?php
$posts_to_exclude = array();
$args = array(
'post_type' => 'wins', // post type you want to offset
'numberposts' => 5 // the default is 5, but you can add for good measure
);
$posts = get_posts( $args );
if ($posts) {
foreach ($posts as $post) {
$posts_to_exclude[] = $post->ID;
}
}
$args = array(
'post_type' => array('wins', 'memes'),
'posts_per_page' => '5',
'post__not_in' => $posts_to_exclude,
'post_status' => 'publish'
);
new WP_Query( $args );
// Do more stuff....
Ad
source: stackoverflow.com
Related Questions
- → CORS missmatch because of http
- → Building sitemap for 2 wordpress install under 1 domain
- → How to remove empty elements after class?(jQuery)
- → Get width of an element and apply to another relative to the first one?
- → How to remove caption p class from wordpress?
- → 301 Redirection from no-www to www in wordpress
- → Laravel 5 routing using prefix
- → WordPress - Header position Top, Left &Right
- → how to add rel=nofollow to some specific external links in wordpress
- → octobercms install error: database is not empty?
- → How to edit the index page of wordpress theme?
- → How to select a Post Type (Wordpress) to pass a filter in head?
- → What sort of URL structure should be used to display AMP HTML vs vanilla HTML
Ad