Reputation: 407
I cant echo the get_post_meta in my html select field.
get_the_id and get_the_title are working fine. Why does "get_post_meta" not work?
<select id="the_event" name="the_event" data-required="no" data-type="select">
<option value="-1">Termine</option>
<?php // WP_Query arguments
$args = array(
'post_type' => array( 'venue' ),
'post_status' => array( 'published' ),
'order' => 'ASC',
'orderby' => 'title',
);
// The Query
$i_query = new WP_Query( $args );
if ( $i_query->have_posts() ) {
while ( $i_query->have_posts() ) {
$i_query->the_post();
?>
<option value="<?php echo get_the_ID(); ?>">
<?php echo get_the_title(); ?> / <?php echo get_post_meta( get_the_ID(), 'venue_ort', true ); ?>
</option>
<?php
}
wp_reset_postdata();
?>
</select>
Any suggestion how I can echo the get_post_meta?
Thanks, Denis
Upvotes: 0
Views: 826
Reputation: 1751
Try using below loop and see if that helps.
Also make sure you have created field in wp-dashboard
<?php
$type = 'venue';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'title'
);
$my_query = null;
$my_query = new WP_Query($args);
?>
<div>
<?php if( $my_query->have_posts() ):?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p>
<?php the_title(); ?>
</p>
<p>
<?php echo get_post_meta($post->ID, 'venue_ort', true); ?>
</p>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
</div>
Upvotes: 1
Reputation: 407
Sorry! I used the wrong meta name. I did not realize that the plugin uses a prefix for the field. It is ptb_venue_ort. With that name it works like charm! Denis
Upvotes: 0
Reputation: 1056
You have forgotten to closed if condition }
Please check below code : Correct code :
<select id="the_event" name="the_event" data-required="no" data-type="select">
<option value="-1">Termine</option>
<?php // WP_Query arguments
$args = array(
'post_type' => array( 'venue' ),
'post_status' => array( 'published' ),
'order' => 'ASC',
'orderby' => 'title',
);
// The Query
$i_query = new WP_Query( $args );
if ( $i_query->have_posts() ) {
while ( $i_query->have_posts() ) {
$i_query->the_post();
?>
<option value="<?php echo get_the_ID(); ?>">
<?php echo get_the_title(); ?> / <?php echo get_post_meta( get_the_ID(), 'venue_ort', true ); ?>
</option>
<?php
}
}
wp_reset_postdata();
?>
</select>
I have checked on my site. It is working now: http://prntscr.com/p3rua6
Thanks
Upvotes: 0