从帖子作者那里获取帖子 - 文字新闻

我正在尝试创建一个部分,显示由创建当前帖子的用户创建的帖子。我需要向他们展示明显排除当前帖子并根据某种类型的帖子(事件)。


我有这个代码,但它不起作用。有人能想到如何帮助我吗?


<?php 


    $args = array(

    'author'        =>  $post->post_author;

    'type'          => $post_meta['_listing_type'][0] == 'event',

    'order'         =>  'ASC',

    'posts_per_page' => -1

    );


    $eventos = get_posts( $args );


    foreach ( $eventos as $evento ) {

        $output .= '<div>'.$evento.'</div>';

    endforeach;


    if(!empty($eventos)) : ?> 


        <div id="listing-eventosartista" class="listing-section">

            <h3 class="listing-desc-headline margin-top-60 margin-bottom-30"><?php esc_html_e('Eventos del artista','listeo_core'); ?></h3>

                <div class="single-item">

                    <?php echo $output; ?>

                </div>


        </div>

    <?php endif ?>


PIPIONE
浏览 56回答 1
1回答

慕勒3428872

你有两件事。你的数组中有一个非法的分号,应该是,我也不完全确定你需要那个奇怪的比较运算符吗?$argstypepost_type试试这个:$args = array(&nbsp; &nbsp; 'author'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=> $post->post_author,&nbsp; &nbsp; 'post_type'&nbsp; &nbsp; &nbsp; => 'event',&nbsp; &nbsp; 'order'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; => 'ASC',&nbsp; &nbsp; 'posts_per_page' => -1);还要确保已设置,具体取决于您调用此内容的位置,可能没有实例化/全局对象。$post$post这也假设你使用的是实际的调用,否则如果你正在检查元字段的常规帖子,你将需要删除参数,并添加一个meta_query参数 - 请注意,这在大型数据库上本质上是很慢的,因为默认情况下表没有索引。另请注意,这是一个数组的数组。post_typeevent'_listing_type'post_typepostmetameta_query该查询最终将如下所示:$args = array(&nbsp; &nbsp; 'author'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=> $post->post_author,&nbsp; &nbsp; 'order'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; => 'ASC',&nbsp; &nbsp; 'posts_per_page' => -1,&nbsp; &nbsp; 'meta_query'&nbsp; &nbsp; &nbsp;=> array(&nbsp; &nbsp; &nbsp; &nbsp; array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'meta_key'&nbsp; &nbsp;=> '_listing_type',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'meta_value' => 'event'&nbsp; &nbsp; &nbsp; &nbsp; )&nbsp; &nbsp; ));
打开App,查看更多内容
随时随地看视频慕课网APP