获取自定义帖子类型数据,包括带有Timber的ACF?

我需要获取用于Timber和Twig的自定义帖子类型数据,使用标准1可以正常工作,例如:

WP_Query

但是,这显然没有ACF字段。

要按照Timber文档中的说明进行以下操作:

// Get the testimonials custom post type posts
$args = array(
    'post_type' => 'testimonial','post_status' => 'publish','perm' => 'readable','nopaging' => true
);

$context['testimonials'] = new WP_Query( $args );

// Restore the global $post to the current post in the main query
wp_reset_postdata();

但是,看来// Get the testimonials custom post type posts $args = array( 'post_type' => 'testimonial','nopaging' => true ); $context['testimonials'] = Timber::get_posts( $args ); 正在获得deprecated in 2.0

似乎最好的方法是使用Timberget_posts,但是由于缺乏文档,我不确定它是或多或少是PostQuery的封装,我可以简单地做像这样:

WP_query

我在正确的轨道上还是正确的方法?

jian385330454 回答:获取自定义帖子类型数据,包括带有Timber的ACF?

好吧,在找到this answer并仔细研究了代码之后,我发现了如何做到这一点,我相信:

expected

据我所知,所有相应的// Get the testimonials custom post type posts $args = array( 'post_type' => 'testimonial','post_status' => 'publish','perm' => 'readable','nopaging' => true ); $query = new Timber\PostQuery($args); // Get an array of post objects $context['posts'] = $query->get_posts(); 参数似乎也可以使用此方法工作-但如果您需要分页工作,我建议您阅读我链接的其他答案,因为它包含有关以下内容的更多信息那。

,

ACF字段在数据库中有一些奇怪的数字键。要获取数据,只需使用自己的功能 get_fields(); https://www.advancedcustomfields.com/resources/get_fields/

本文链接:https://www.f2er.com/2669376.html

大家都在问