Insert Custom Post Type content into Category term-description
Support › MB Custom Post Type › Insert Custom Post Type content into Category term-descriptionResolved
- This topic has 3 replies, 2 voices, and was last updated 2 years, 6 months ago by
Denise Field.
-
AuthorPosts
-
November 15, 2022 at 12:39 AM #39135
Denise Field
ParticipantHi
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. InstalledInsert Page
Plugin so I can insert a piece of shortcode
2. I created a custom field calledalt_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 IDadd_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 acustom 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?
November 15, 2022 at 10:42 PM #39150Peter
ModeratorHello 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 thealt-category
post content to the WooCommerce product category description2. But there is no connection or relationship between product category and
alt-category
post to get the CPTalt-category
post ID.3. What is the object that you assign the custom field
alt_page_id
to? CPTalt-category
or product category? Product category is a taxonomy so if you want to get the term metaalt_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.
November 16, 2022 at 2:58 AM #39157Denise Field
ParticipantThank you, its now working!
November 16, 2022 at 5:14 AM #39159Denise Field
ParticipantFor 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!
-
AuthorPosts
- You must be logged in to reply to this topic.