在自定义帖子类型中循环生成文本形式的the_title


Loop within custom post type generating the_title as text

寻找一个ACF自定义帖子类型php瘾君子来帮助我解决这个问题。我在这里找不到像这样的其他问题,所以我可能会找到最佳实践解决方案,但希望不是!

在特定帖子类型

中,我正在尝试循环加载另一种帖子类型。

作为一个实际的例子,在每个社区中,我想动态列出公寓。

我最初的想法是做一个 ACF 复选框,列出邻域标题,以便值属性动态加载邻域的the_title。

这有效,但由于某种原因,负载也会the_title作为循环上方的文本拉入。

思潮?(下面的代码)

        <?php
        $apartments = query_posts(array(
            'meta_query' => array(
                array(
                    'key' => 'apartment_neighborhood',
                    'value' => the_title(),
                    'compare' => 'LIKE'
                    )
            ),
            'post_type' => 'apartments', 
            'orderby'=> 'title', 
            'order' => 'ASC' ));
        $loop = new WP_Query( $apartments );
        ?>
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

使用 get_the_title();,因为它在打印the_title();时返回值

 <?php
        $apartments = query_posts(array(
            'meta_query' => array(
                array(
                    'key' => 'apartment_neighborhood',
                    'value' => get_the_title(),
                    'compare' => 'LIKE'
                    )
            ),
            'post_type' => 'apartments', 
            'orderby'=> 'title', 
            'order' => 'ASC' ));
        $loop = new WP_Query( $apartments );
        ?>
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

参考这里

获取标题