我想你听到的是“蟋蟀”,因为这其中有几个成分。您需要:
创建一个元框,保存该元框中的数据,并在前面为#1和#2构建一个循环:
function add_featured_meta_box() {
add_meta_box("featureddiv", "Featured Post", "featured_post_meta_box", \'post\', "side", "low");
}
add_action("do_meta_boxes", "add_featured_meta_box");
function featured_post_meta_box(){
global $post;
$custom = get_post_custom($post->ID);
$featured = (!empty($custom["_featured"][0])) ? $custom["_featured"][0] : \'\'; ?>
<table>
<tr>
<td>Featured
<td> <input type="checkbox" name="featured" <?php checked($featured,true); ?> /> </td>
</tr>
</table><?php
}
function save_featured_meta($postid,$post){
global $_POST;
// set the ID to the parent post, not the revision
$postid = (wp_is_post_revision( $postid )) ? wp_is_post_revision( $post ) : $postid;
$post_type = get_post_type( $postid );
if (isset($_POST[\'featured\'])) {
update_post_meta($postid, "_featured", true);
} else {
delete_post_meta($postid, "_featured", true);
}
}
add_action(\'save_post\', \'save_featured_meta\', 1, 2);
对于#3:
$args = array(
\'post_type\' => \'post\',
\'ignore_sticky_posts\' => true,
\'meta_query\' => array(
array(
\'key\' => \'_featured\',
\'value\' => true,
)
)
);
$query = new WP_Query( $args );
几乎未经测试。可能是马车
排空警告。不退款。