You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Elementor Pro文章组件无法显示ACF关联字段内容的问题

问题:Elementor文章组件无法显示ACF关联的自定义文章类型内容

场景说明

  • 基于Elementor Pro搭建网站,创建了名为「Encyclopedia」的自定义文章类型
  • 通过ACF添加了返回文章ID的关联字段「related_topics」
  • 为实现关联内容查询,在functions.php中添加了以下自定义查询代码:
add_action( 'elementor/query/related_topics_query', function( $query ) { 
    $meta_query = $query->get( 'meta_query' ); 
    $meta_query[] = [ 
        'key' => 'related_topics', // ACF relationship field name 
        'value' => get_the_ID(), 
        'compare' => '=', 
    ]; 
    $query->set( 'meta_query', $meta_query ); 
} );
  • 在Elementor文章组件的Query ID字段中填入了「related_topics_query」

问题现象

文章组件未显示关联的Encyclopedia类型文章,反而展示了网站其他区域的普通文章。

解决方案

使用子主题时,上述自定义查询代码必须放置在子主题的functions.php文件中,不能通过插件加载PHP代码。

内容的提问来源于stack exchange,提问作者Jeff Wirth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 09:32:36