Custom Fields
Re-Envisioned
Support MB Custom Post Type How do I integrate custom post with sidebar?

This topic contains 5 replies, has 2 voices, and was last updated by  Anh Tran 1 year, 2 months ago.

  • Creator
    Topic
  • #10499
    Resolved
    dd32137
    Participant

    Hi,

    I’ve created a custom post type. I’ve also created a MetaBox. I’ve added the PHP code to my single.php file and set the “field_id”. My problem is that I can’t figure out how to get the MetaBox to tie to the Post Type and then put them into the sidebar. I figure the sidebar should be easy enough because I can use custom html so I should be able to insert shortcode into the sidebar component to solve that. At the moment, I’m not getting any error messages, but it is not displaying the post either.

    What am I missing?

    I appreciate your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #10513

    Anh Tran
    Keymaster

    Hello,

    Can you give me more details on “get the MetaBox to tie to the Post Type and then put them into the sidebar”? Do you mean registering a meta box (with custom fields) for the custom post type and outputting the custom fields’ values in the sidebar?

    #10521

    dd32137
    Participant

    Yes, that sounds correct.

    #10534

    Anh Tran
    Keymaster

    Hi, to register a meta box for a custom post type, please:

    • Go to Meta Box > Custom Fields, click Add New to add a new field group.
    • Then add fields you want from the left panel.
    • Click the tab Settings and select “Posts” in “Show for”, and then select your post type below.
    • Click Save Changes button

    Now go back to your custom post type edit screen and you’ll see the meta box appear. Enter some info and update the post.

    To show the custom fields’s values in the sidebar, there are 2 ways:

    • Put the shortcode [rwmb_meta meta_key="your_field_id"] into the text widget. See this docs for more details.
    • Or you can edit your sidebar.php file of your theme and add some code to display the fields. See this docs for more info.
    #10624

    dd32137
    Participant

    Ok, I’ve done everything you said…with a couple of differences where my screen didn’t match your description. I see the metabox in my custom post type, so that’s great. The problem I’m having now is that no matter what I do, it still won’t show in the side bar.

    I’ve added a text widget to my sidebar and pasted the [rwmb_meta meta_key="mbQuotes"] in the Text tab. Nothing shows up.

    I’ve added a text widget to my sidebar and pasted the code into the Visible tab. It shows the code and not the value of the post.

    I’ve added a Shortcode Widget to my sidebar and pasted the code in there. Nothing Shows.

    I’ve tried changing the mbQuotes (name of Metabox) to the actual field name within the metabox (txtQuotes) but got nothing.

    I’m at a loss now.

    #10637

    Anh Tran
    Keymaster

    Hi, do your fields have any prefix? In the shortcode, the meta_key should be the full field ID, including the prefix (if any).

    If you still have any trouble showing the data, please send me an email via the contact form.

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.