admin管理员组文章数量:1122846
I have a Wordpress blog with regular posts on the homepage of my website. But I have a custom post type called "buildings_post_type". And I want the second and third most recently published buildings post to appear in the second and third position on the blog.
With the following code I can integrate a specific ordinary post (with the ID 33) into the blog in the third position. But that doesn't help me yet.
function insert_post_wpse_33($posts) {
global $wp_query;
$desired_post = 33;
if (is_main_query() && is_home() && 0 == get_query_var('paged')) {
$p2insert = new WP_Query(array('p'=>$desired_post,'suppress_filters'=>true));
$insert_at = 3;
if (!empty($p2insert->posts)) {
array_splice($posts,$insert_at,0,$p2insert->posts);
}
}
return $posts;
}
add_filter('posts_results','insert_post_wpse_33', 45);
This, in turn, is intended to integrate the last post of various custom post types:
query_posts( array(
'post_type' => array( 'custom_post1', 'custom_post2', 'custom_post3',
'custom_post4' ),
'cat' => 3,
'showposts' => 5 )
);
Would anyone know how I can make a plugin out of what I want to achieve?
本文标签: Integrate the second most recent custom post into the Wordpress blog
版权声明:本文标题:Integrate the second most recent custom post into the Wordpress blog 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307530a1933343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论