WP: шорткод для вывода записи

26 марта, 2018

Чтобы вывести запись в произвольном месте шаблона или страницы.

function tr_post_include($atts) {
      $thepostid = intval($atts[id]);
      $output = '';
      query_posts("p=$thepostid");
      if (have_posts()) : while (have_posts()) : the_post();
            $output .= get_the_content($post->ID);
            endwhile; else:
      endif;
      wp_reset_query();
      return $output;
}
add_shortcode("post_inc", "tr_post_include");

Теперь в любом месте можно использовать шорткод [post_inc id="XX"], где XX — это id нужной записи.

Источник: http://n-wp.ru