0
votes

I am building a custom post type and looking for a solution either to have a custom meta box on there so that the admin could choose which page the custom post type appears on.

E.g. I have a custom post type called Testimonials.

This is a list of testimonials on a page which contains a featured image, the title, and the content.

There will be a page which all are listed and I can do this using a standard WP Query

On certain pages (e.g. about, news, case-studies) I want to be able to print testimonials in the sidebar of the page. A certain testimonial that the admin can choose from a drop down to put the testimonial on that page.

1 Testimonial per page.

I look forward to your response and feedback

2

2 Answers

2
votes

You can add a custom meta box to the custom post type using add_meta_box.

http://codex.wordpress.org/Function_Reference/add_meta_box

add_meta_box(
    'meta_box_id', //The ID of the Meta Box
    'Meta Box Title', //The Title of the Meta Box
    'meta_box_id_meta_box', //Callback Function
    'page', //Post type to apply to, in this case you would want 'page', or the ID of a Custom Post Type
    'normal', //Priority 
    'default' //Callback Agruments
);

You can find out more information about how this function is added to a hook, saved etc. here: http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/

From there, you just need to make a select menu that consists of all of the page IDs for your custom content type (by using WP_Query, and looping through the results). When you save the form, it saves the ID, and then you use that ID in conjunction with your WP_Query to pull the single post and display it on the page template.

0
votes

I can't say I'm 100% clear on your requirements, but to link WordPress posts I've found the Posts 2 Posts plugin to be very useful. I've used it to link two different custom post types together, but I'm sure you could use it to link a custom post type to a page.