Ask your WordPress questions! Pay money and get answers fast! (more info)

Display Post Meta attached to one page, on every page. WordPress

  • SOLVED

Hello,

I have some post_meta attached to a homepage.


$meta_boxes[] = array(
'id' => 'menu_tile_one',
'title' => 'Menu Tile One',
'pages' => array('page'),
'fields' => array(


array(
'name' => __( 'Image', 'rwmb' ),
'desc' => __( '592px / 900px' ),
'id' => "{$prefix}menu_tile_one_image",
'type' => 'image_advanced',
'max_file_uploads' => 1,
'clone' => false,
)


)
);



I am trying to display this post meta from (page id7) ON EVERY PAGE, not just the page that it is attached to in the admin.


<?php $images = rwmb_meta( 'meta_menu_tile_one_image', 'type=image&size=full');?><?php foreach ( $images as $image ){echo "<img src='{$image['url']}' class='first' alt='' title='' />";} ?>


The above code works on the page that the meta is attached, however it does not work on every page.

Any ideas?

Answers (3)

2014-08-27

Dbranes answers:

I wonder if you are missing the third input argument, which is <em>$post_id</em>. It's the current post id by default:

<strong>Example:</strong>


$post_id = 7; // You can change this to get_the_ID() as well.
$images = rwmb_meta( 'meta_menu_tile_one_image', 'type=image&size=full', $post_id );


Nick comments:

Thanks, that's it I think!


Dbranes comments:

@Nick, great!


Dbranes comments:

ps: this is the function definition:

/**
* Get post meta
*
* @param string $key Meta key. Required.
* @param int|null $post_id Post ID. null for current post. Optional
* @param array $args Array of arguments. Optional.
*
* @return mixed
*/
function rwmb_meta( $key, $args = array(), $post_id = null )
{
return RWMB_Helper::meta( $key, $args, $post_id );
}


so you can see all the input parameters.

2014-08-27

Remy answers:

What is this rwmb_meta function ?


Nick comments:

https://github.com/rilwis/meta-box


Remy comments:

You need to add the $post_id value of your homepage in the function


<?php $images = rwmb_meta( 'meta_menu_tile_one_image', 'type=image&size=full', 7);?><?php foreach ( $images as $image ){echo "<img src='{$image['url']}' class='first' alt='' title='' />";} ?>

2014-08-27

timDesain Nanang answers:

You need to add the page_id to the rwmb_meta function
try this:
<?php
$images = rwmb_meta( 'meta_menu_tile_one_image', 'type=image&size=full', 7);?><?php foreach ( $images as $image ){echo "<img src='{$image['url']}' class='first' alt='' title='' />";}
?>