我无法通过帖子中的下拉元数据查询我想要的帖子..我最终的目标是为精选帖子1,2,3等创建元框,但需要知道如何显示这些元素。有帮助吗?感谢
// ADD ALL OUR META BOX STUFF
add_action('add_meta_boxes', 'voodoo_meta_box');
function voodoo_meta_box() {
add_meta_box('voodoo_title_link', 'Link Format Title URL', 'voodoo_title_link', 'post', 'side', 'default');
}
// SET UP THE TITLE LINK META BOX
function voodoo_title_link() {
global $post;
// NONCENAME NEEDED TO VERIFY WHERE THE DATA ORIGINATED
echo '<input type="hidden" name="voodoo_meta_noncename" id="voodoo_meta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
// GET EXISTING DATA IF IT'S ALREADY BEEN ENTERED
$voodoo_dropdown = get_post_meta($post->ID, 'voodoo_dropdown', true);
?>
<fieldset id="voodoo-div">
<div>
<p>
<label for="voodoo_dropdown" >Dropdown Options:</label><br />
<select name="voodoo_dropdown" id="voodoo_dropdown">
<option<?php selected( get_post_meta($post->ID, 'voodoo_dropdown', true), 'USA' ); ? >>USA</option>
<option<?php selected( get_post_meta($post->ID, 'voodoo_dropdown', true), 'Canada' ); ?>>Canada</option>
<option<?php selected( get_post_meta($post->ID, 'voodoo_dropdown', true), 'Mexico' ); ?>>Mexico</option>
</select>
</p>
</div>
</fieldset>
<?php
}
// GOTTA SAVE THE METADATA OF COURSE
function voodoo_save_meta($post_id, $post) {
// CHECK THIS CAME FROM THE RIGHT SCREEN WITH PROPER AUTHENTICATION
// SINCE SAVE POST CAN BE TRIGGERED OTHER WAYS
if ( !wp_verify_nonce( $_POST['voodoo_meta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
// CAN WE EDIT THE POST OR PAGE?
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
// AFTER AUTHENTICATION WE NEED TO FIND AND SAVE THE DATA
// PUT IT IN AN ARRAY TO MAKE IT EASIER TO LOOP THROUGH
$voodoo_meta['voodoo_dropdown'] = $_POST['voodoo_dropdown'];
// ADD VALUES OF $voodoo_meta AS CUSTOM FIELDS
foreach ($voodoo_meta as $key => $value) { // LOOP THROUGH THE $voodoo_meta ARRAY!
if( $post->post_type == 'revision' ) return; // DON'T STORE THE DATA TWICE
$value = implode(',', (array)$value); // IF $value IS IN AN ARRAY, MAKE IT A CSV (unlikely)
if(get_post_meta($post->ID, $key, FALSE)) { // IF CUSTOM FIELD ALREADY HAS A VALUE
update_post_meta($post->ID, $key, $value);
} else { // AND IF IT DOESN'T ALREADY HAVE A VALUE
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); // DELETE IF IT'S EMPTY
}
}
add_action('save_post', 'voodoo_save_meta', 1, 2); // SAVE THE CUSTOM FIELDS
PHP主页
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => array( 'post' ),
'meta_key' => 'voodoo_meta',
'meta_value' => 'Canada',
'showposts' => 1
);
$wp_query = new WP_Query( $args );
if ( have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();?>
<div id="listing-container">
<a href="<?php the_permalink() ?>"><div class="listing-ftimg"><div class="postborder"></div><div class="posteximgzoom"></div><?php the_post_thumbnail( 'blog-posts' ); ?></div></a>
<div class="listing-title"><h12><a href="<?php the_permalink() ?>"><?php the_titlesmall('', '...', true, '50') ?></a></h12></div>
<div class="favourite-post"> </div>
<div class="date-cat-post"><span class="datehomelisting"><?php the_time('F jS, Y') ?> · </span><span class="categoryhomelisting"><?php $category = get_the_category(); echo $category[0]->cat_name; ?></span></div>
<div class="excerpt-post">
<p class="excerptlisting"><?php echo excerpt(40); ?></p>
</div>
<a href="<?php the_permalink() ?>"><div class="readmorebutton"><span class="readmorep">Read More</span></div></a>
</div>
<div class="seplisting"></div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
感谢提前