Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义帖子类型内容不显示在单个页面上_Php_Wordpress_Plugins - Fatal编程技术网

Php 自定义帖子类型内容不显示在单个页面上

Php 自定义帖子类型内容不显示在单个页面上,php,wordpress,plugins,Php,Wordpress,Plugins,我在“管理”面板中的自定义帖子类型上添加了“选择”下拉列表。基本上,这是一个选择下拉列表,显示我的其他自定义文章类型标题。我使用了下面的代码 $args = array( 'post_type'=>'blogauthor','post_status' => 'publish' ); $recent_posts = wp_get_recent_posts($args); $getblogauthorId=get_post_meta(get_the_ID(), 'blog

我在“管理”面板中的自定义帖子类型上添加了“选择”下拉列表。基本上,这是一个选择下拉列表,显示我的其他自定义文章类型标题。我使用了下面的代码

$args = array( 'post_type'=>'blogauthor','post_status' => 'publish' );
    $recent_posts = wp_get_recent_posts($args);
    $getblogauthorId=get_post_meta(get_the_ID(), 'blogauthor', true );// get selected when hit URL page
    echo '<select name="blogauthor">
            <option  value="" selected="" disabled="">Select Author</option>';
    foreach( $recent_posts as $recent ){
        if($recent["ID"]==$getblogauthorId){ $authselected='selected="selected"';};
        echo'<option value="' .$recent["ID"].'" '.$authselected.'>' .   $recent["post_title"].'</option> ';
    }
echo'</select>';

我尝试了“meta\u query”=>array(array('key'=>'blogauthor','value'=>$blogauthorId,),但仍然存在相同的问题。您确定
get\u post\u meta
实际返回了预期值(或任何值)对于
$blogauthorId
?您是否尝试将其打印出来以查看其返回的内容?@FluffyKitten,该代码有任何问题吗?因为我打印了$blogauthorId,我得到了192,这是正确的。使用echo“”;print_r($authorData);echo“”;获取其内部请确认您的查询正在返回对象
$blogauthorId=get_post_meta(get_the_ID(), 'blogauthor', true );
        $the_query =array(
          'post_type'              => array( 'blogauthor' ),
          'post_status'            => array( 'publish' ),
          'meta_query'             => array(
                               array(
                             'key'       => 'blogauthor',
                             'value'     => $blogauthorId
                            )
                           ),
      'order'      => 'DESC'
    );
        $authorData = new WP_Query($the_query);
        if ($authorData->have_posts()): while($authorData->have_posts()): $authorData->the_post();
        echo"<pre>";
        //var_dump(get_the_content());
        var_dump(get_the_content($authorData->ID));
        endwhile; else:
        echo "Please select author";

        endif;
Array
(
    [post_type] => Array
        (
            [0] => blogauthor
        )

    [post_status] => Array
        (
            [0] => publish
        )

    [meta_query] => Array
        (
            [0] => Array
                (
                    [key] => blogauthor
                    [value] => 191
                )

        )

    [order] => DESC
)