WordPress apply_filters( 'the_content', 'func_name' ) 在另一个钩子中不起作用

帕塔维·帕特尔

我正在尝试根据满足的某些条件产品单页中显示PAGE 内容。

我在产品单页的特定动作挂钩位置显示此页面内容,如下代码所示:

add_filter( 'wp', array( $this, 'txb_add_page_check_single' ) );
public function txb_add_page_check_single() { 

    if ( is_single() ) {

        if ( some_condition_met ) {
            add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'txb_display_page_content_single' ) );
        }

    }

}

public function txb_display_page_content_single() {

    $txb_all_data_array = get_post( $some_page_id );

    //echo apply_filters( 'the_content', get_post_field( 'post_content', $txb_all_data_array->ID ) ); // CASE 1 : NOT WORKING

    $get_content_data = $txb_all_data_array->post_content;
    echo $get_content_data; //CASE 2 : Working
}

这里// CASE 1不工作。

// CASE 1正在返回CURRENT SINGLE PRODUCT CONTENT,但我想要 PAGE CONTENT $some_page_id

我想让它使用// CASE 1,因为 Content 可能有 Shortcode 或任何其他 Gutenberg 块。

PS:钩子名称woocommerce_after_add_to_cart_quantity将根据满足的某些条件动态出现。

希姆斯五世

将此代码放在活动主题的 functions.php 文件或自定义插件的主文件中

add_filter('se152488_the_content', 'wptexturize');
add_filter('se152488_the_content', 'convert_smilies');
add_filter('se152488_the_content', 'convert_chars');
add_filter('se152488_the_content', 'wpautop');
add_filter('se152488_the_content', 'shortcode_unautop');
add_filter('se152488_the_content', 'prepend_attachment');

然后,像这样调用内容:

echo apply_filters(  'se152488_the_content' , $txb_all_data_array->post_content  );

信用:https ://wordpress.stackexchange.com/a/152493/110795

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在wordpress插件上使用the_content钩子

了解wordpress the_content

从 WordPress 中的“the_content”功能中剪切文本

wordpress the_content()未在正确的div中显示

需要从the_content()获取所有<img>;在WordPress中?

在 WordPress 中 the_content() 前后添加内联图标

从 the_content WordPress 中删除带有 ID 的 div

从一个页面获取the_content并在另一页面中显示(Wordpress)

WordPress的the_content(); 显示内容和附件

wordpress-如果bbpress显示the_content()

serverless.yml中http事件的函数“ func_name”中的“ path”属性丢失或无效

从WooCommerce中的apply_filters('prefix_xml_feeds_productname_variant')函数获取数据

apply_filters 不回显无序列表中的列表项

WordPress:get_the_content()和the_content()之间的区别

有条件的“ the_content”过滤器wordpress

Wordpress the_content()输出文档类型声明

如何在WordPress中分离帖子的the_content

WordPress 将 php 代码运行到 the_content 循环中

尝试从the_content中删除三个或更多<br>

WordPress的Woocommerce钩子woocommerce_before_main_content不起作用

从the_content删除一些html标签

致命错误:在第317行的/public_html/wp-includes/load.php中调用未定义的函数apply_filters()

如何在the_content();中将图像包装在div中?

将the_content()存储到javascript / jquery变量中

特殊字符移到the_content中的行首

通过ID获取the_content并在WordPress中保留<p> -tag

WordPress:front-page.php上的the_content过滤器

'future_to_publish'钩子在wordpress中不起作用

仅输出到 the_content() 的第一个实例