Insert Custom Post Type content into Category term-description

Support MB Custom Post Type Insert Custom Post Type content into Category term-descriptionResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #39135
    Denise FieldDenise Field
    Participant

    Hi

    I have created a custom post type called alt-category and additionally created a custom template which I have assigned to a new post.

    I want to insert the content of that post into my category description.

    This is where I am at so far:
    1. Installed Insert Page Plugin so I can insert a piece of shortcode
    2. I created a custom field called alt_page_id
    3. I created a hook and function in my functions.php - at the moment all I have is a post ID no shortcode - I just want to see if I can get that Post ID

     
    add_action( 'woocommerce_after_main_content', 'add_alt_description', 10 );
    
    function add_alt_description(){
    	$current_cat_id = get_queried_object_id();//This gets the correct Category ID for the page I want
    	echo $current_cat_id;
    	$value = rwmb_the_value( 'alt_page_id','' , $current_cat_id ) ;//This is supposed to display the post ID
    	echo  $value;
    }

    4. The format I need to display the shortcode using the $value as a variable is
    [insert post='$value' display='content']

    I have 2 issues
    1. The $current_cat_id does give me the correct category but the $value variable is outputting nothing
    2. in item 4, as I have a custom post type I'm not sure what to put after [insert should it be my custom post type slug? e.g. alt-category.

    Can you help?

    #39150
    PeterPeter
    Moderator

    Hello Denise,

    1. Let me explain your case again and let me know if it is incorrect.

    - You have a CPT alt-category
    - You want to show the alt-category post content to the WooCommerce product category description

    2. But there is no connection or relationship between product category and alt-category post to get the CPT alt-category post ID.

    3. What is the object that you assign the custom field alt_page_id to? CPT alt-category or product category? Product category is a taxonomy so if you want to get the term meta alt_page_id, you need to pass the second argument to the helper function

    $value = rwmb_meta( 'alt_page_id', ['object_type' => 'term'], $current_cat_id );
    echo $value;

    Read more on the documentation https://docs.metabox.io/extensions/mb-term-meta/#getting-field-value

    4. Regarding the insert post shortcode, I dont know what type of value it need to display the post content. Please contact their support for further assistance.

    #39157
    Denise FieldDenise Field
    Participant

    Thank you, its now working!

    #39159
    Denise FieldDenise Field
    Participant

    For reference if anyone else wants to use that plugin the entire function to display the custom post is

    
    add_action( 'woocommerce_after_main_content', 'add_alt_description', 10 );
    
    function add_alt_description(){
    	$term_id = get_queried_object_id();
    	$value = rwmb_meta( 'alt_page_id', ['object_type' => 'term'], $term_id );
    	echo '<div class="container"><div class="alt-category"><div class="alt-category__page"><div class="alt-category__content"> ' ;
    	
    	echo do_shortcode("[insert page='$value' ]");
    	echo '</div></div></div></div>'; 
    
    }
     
     

    *** The insert page shortcode does strip all the divs from the page you may have set up for styling so I just added them back in with this function ***

    This was just perfect for large content to display in the product category pages, so much better than the tiny box woocommerce gives you!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.