Home > Software design >  WordPress apply_filters( 'the_content', 'func_name' ) not working inside another
WordPress apply_filters( 'the_content', 'func_name' ) not working inside another

Time:03-24

I am trying to display PAGE Content inside Product Single Page based on some conditions met.

I am showing this Page Content at a particular action hook place of Product Single Page as shown in below code :

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
}

Here // CASE 1 is not working.

// CASE 1 is returning a CURRENT SINGLE PRODUCT CONTENT, but I want PAGE CONTENT of $some_page_id.

I want to get it work with // CASE 1 , Because Content may have Shortcode or any other Gutenberg block.

PS : hook name woocommerce_after_add_to_cart_quantity will come dynamically , based on some conditions met.

CodePudding user response:

Place this code in your active theme's functions.php file OR Custom Plugin's main file

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');

then , call content like this :

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

Credit : https://wordpress.stackexchange.com/a/152493/110795

CodePudding user response:

The variable $some_page_id needs to be set, its passing null and you're getting the CURRENT SINGLE PRODUCT CONTENT.

  • Related