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