dongzhuan1185 2018-10-15 17:31
浏览 99

按ID获取自定义帖子类型的帖子内容

I'm trying to fetch specific post content by ID for a custom post type.

I've tried the following solutions and a few more. At best I seem to be retrieving the title. But none of the content.

1:

<?php
$post_id = 15002;
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
echo $queried_post->post_content;
?>

2:

<?php
$my_postid = 15002;
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
echo $content;
?>

3:

<?php 
    $ID = 15002;
    $args = array('p' => $ID, 'post_type' => 'ct_template');
    $loop = new WP_Query($args);
    ?>

    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <?php global $post; ?>
        <?php the_content () ?>
    <?php endwhile; ?>
  • 写回答

1条回答 默认 最新

  • doucheng1063 2018-10-16 06:06
    关注

    If you are using Toolset and want to get content by page Id then use below code in your function.php

    add_filter( 'wpv_filter_content_template_output', 'get_content_template_id', 99, 4 );
    function get_content_template_id( $content, $template_selected, $id, $kind ) {
        global $current_archive_template_id;   
        $current_archive_template_id = $template_selected; // $template_selected = current Content Template ID
        return $content;
    }
    

    Then use below code to get title and content

    $content_template_title = get_the_title($current_archive_template_id);
    $content_template_content = get_the_content($current_archive_template_id);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大