Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Echo content of meta into custom page query WordPress

  • SOLVED

Hello,

I am using a script that styles my custom fields, allows me to enter data and echo anywhere … it works, but how could I echo this content such as an ID into this query?

Thanks!


<?php if(get_post_meta($post->ID, 'krp_sidebar_id', true)):?>

<strong><?php echo get_post_meta($post->ID, 'krp_sidebar_id', true);?> </strong>

<?php $my_query = new WP_Query("showposts=1&post_type=page&page_id=<strong>ECHO HERE</strong>");
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>

<?php the_content('Read the rest of this entry &raquo;'); ?>

<?php endwhile; ?>

<?php else:?>

Somthing

<?php endif;?>

Answers (2)

2010-08-11

enodekciw answers:

<?php if(get_post_meta($post->ID, 'krp_sidebar_id', true)):?>
<?php <strong>$sidebarid</strong> = get_post_meta($post->ID, 'krp_sidebar_id', true);?>
<?php $my_query = new WP_Query("showposts=1&post_type=page&page_id="<strong> . $sidebarid</strong>);
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<?php the_content('Read the rest of this entry &raquo;'); ?>
<?php endwhile; ?>
<?php else:?>
Somthing
<?php endif;?>


try this ;)


West Coast Design Co. comments:

Hi,

Thanks for taking the time to post the full source code … tried Konrad’s snippet, with no luck; maybe my eyes are just tired!

Thank again,

2010-08-11

Konrad Karpieszuk answers:

try this (i show only second and third line of your code with my changes):

<?php $myID = get_post_meta($post->ID, 'krp_sidebar_id', true);?>

<?php $my_query = new WP_Query("showposts=1&post_type=page&page_id=" . $myID);