the_content is displaying nothing for a costum pos

2019-08-07 06:09发布

问题:

When I was using the default post type in Wordpress, the code above was working well. But with custom post types, It is displaying nothing.

   <?php
    $p=$_GET['p'];

    header('Content-Type: text/html; charset: UTF-8');
    require( '../../../../wp-load.php' );

    $my_query = new WP_Query();
    $my_query->query(array( 'post__in' => array($p)));

    if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); 

    echo the_content();


    endwhile;
    endif;
    ?>

Your help is highly appreciated

回答1:

Custom post types are not posts.

So the solution is:

$my_query->query(array('post_type' => 'aya-bi-aya', 'post__in' => array($p)));

Looking hours for solution, and finding it minutes after posting question on SO