WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the Types Plugin for Wordpress and created a custom field. I would like to display this custom field in the sidebar of all of my pages. The problem is that it only displays in the sidebar of the page I created the custom field on. It does NOT display in the sidebar on any of the other pages. Here's the code I placed in my generic sidebar.php file:

<?php echo(types_render_field("photo", array("alt"=>"Product image", "width"=>"300","height"=>"200","proportional"=>"true"))); ?>

Any ideas on how to get it to display in the sidebar of ALL the pages? I'm using the Twenty eleven theme with the latest version of Wordpress.


share|improve this question
Did you just add one photo? – offroff Apr 12 '12 at 12:50
yes. But, this is just one example. No matter what i use as a custom field, text box, text area, etc, it only displays in the sidebar on the page the custom field was created on. – Tory Apr 12 '12 at 13:03
Did you try to add "photo" on another page as well? – offroff Apr 12 '12 at 13:09
Yes, and then the photo will appear in the sidebar of that page, as well. But, I don't want to have to add the photo to every page on my site to get it to appear in the sidebar. Or maybe I'm not understanding you. A little more info, I'm using a different page template on each page and the custom field options are specific to each page template. Maybe that has something to do with it?? – Tory Apr 12 '12 at 13:16
Ok, but if you want the same photo on all pages you should add a widget with a photo in it. The function you use are supposed to just show information from the current page – offroff Apr 12 '12 at 13:20

I checked the code in the repository, and this specific function doesn't have an ID parameter, meaning that it only grabs the CF of the current post/page being displayed.

A fast solution would be:

$my_page = get_page_by_path( 'my-page' );
$meta_values = get_post_meta($my_page->ID, 'custom-field-name', true);

Maybe the plugin has another function for that, but you'd better ask in the plugin support page http://wordpress.org/tags/types?forum_id=10

share|improve this answer
Thanks for the reply! I added that code to my sidebar.php file and it didn't work. I changed 'my-page' to the page name and replaced'custom-field-name' with the custom field name and nothing appeared at all. – Tory Apr 12 '12 at 14:15
Hey brasofilo, I put this in my sidebar: <?php $about_page = get_page_by_title('sidebar'); echo "$about_page->post_content"; ?> and I got the custom field shortcode to appear in every sidebar, but not the actual content of the custom field. This what is appearing now: [types field="sidebartitle"][/types] But there is smart quotes which is maybe why it's displaying the short code and not the actual content? – Tory Apr 12 '12 at 14:40
hi, Tory, I'm not sure if this is what you need echo do_shortcode($about_page->post_content);. . . Did you managed to get the desired custom field content using get_post_meta? – brasofilo Apr 12 '12 at 17:42
Here's what ended up working for me: $args=array( 'page_id' => 39, 'post_type' => 'page', 'post_status' => 'publish', ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php the_content(); endwhile; } wp_reset_query(); // Restore global post data stomped by the_post(). ?> Thanks for your help. – Tory Apr 12 '12 at 18:09

A dirty solution:

$custom_image = types_render_field("photo", array("alt"=>"Product image","width"=>"300","height"=>"200","proportional"=>"true");
if($custom_image) {
    // this page has a custom photo. Print it.
    print $custom_image;
} else {
   // this page don't have a photo, therefore we output the photo of the default page
   $id = 1; // the id of the default page
   $post = get_post($id);
   print types_render_field("photo", array("alt"=>"Product image","width"=>"300","height"=>"200","proportional"=>"true");

Or if you really want the same photo everywhere then just use what's in the else clause

share|improve this answer

Not sure since when, but you can pass the post id as an argument

$postid = get_the_ID();
echo(types_render_field("photo", array("post_id"=>"$postid","alt"=>"Product image", "width"=>"300","height"=>"200","proportional"=>"true"))); 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.