Wordpress,在admin中搜索自定义帖子类型,返回多个帖子类型

时间:2014-02-24 10:24:06

标签: php wordpress

我有3种自定义帖子类型,所有似乎都已注册好了。 他们被称为“表演者”,“活动”和“场地”(这是一个音乐网站)

但是......在WP管理员中,当我列出“所有表演者”并进行搜索时,结果包括所有三种自定义帖子类型。

奇怪的是,总计数是正确的,但显示的结果包括所有自定义帖子类型。

此外,当我在第一次搜索后直接进行第二次搜索时,我收到了无效的帖子类型错误。在查询字符串中,此时,post_type = Array,我猜是为什么。

不是复制大量代码,而是表演者的register_post_type,也许我错过了什么? [edit]按要求提供完整代码...

非常感谢任何帮助!!

function my_custom_post_performer(){

$labels = array(
    'name'               => _x( 'Performers', 'post type general name' ),
    'singular_name'      => _x( 'Performer', 'post type singular name' ),
    'add_new'            => _x( 'Add New', 'book' ),
    'add_new_item'       => __( 'Add New Performer' ),
    'edit_item'          => __( 'Edit Performer' ),
    'new_item'           => __( 'New Performer' ),
    'all_items'          => __( 'All Performers' ),
    'view_item'          => __( 'View Performer' ),
    'search_items'       => __( 'Search Performers' ),
    'not_found'          => __( 'No performers found' ),
    'not_found_in_trash' => __( 'No performers found in the Trash' ), 
    'parent_item_colon'  => '',
    'menu_name'          => 'Performers'
);
$args = array(
    'labels'        => $labels,
    'description'   => 'Holds our performers and performer specific data',
    'public'        => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
    'has_archive'   => true,
);
register_post_type( 'performer', $args );

}

add_action( 'init', 'my_custom_post_performer' );

function my_updated_performer_messages( $messages ) {
global $post, $post_ID;
$messages['performer'] = array(
    0 => '', 
    1 => sprintf( __('Performer updated. <a href="%s">View performer</a>'), esc_url( get_permalink($post_ID) ) ),
    2 => __('Custom field updated.'),
    3 => __('Custom field deleted.'),
    4 => __('Performer updated.'),
    5 => isset($_GET['revision']) ? sprintf( __('Performer restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    6 => sprintf( __('Performer published. <a href="%s">View performer</a>'), esc_url( get_permalink($post_ID) ) ),
    7 => __('Performer saved.'),
    8 => sprintf( __('Performer submitted. <a target="_blank" href="%s">Preview performer</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    9 => sprintf( __('Performer scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview performer</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    10 => sprintf( __('Performer draft updated. <a target="_blank" href="%s">Preview performer</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;

}

add_filter( 'post_updated_messages', 'my_updated_performer_messages' );

function performer_info_box() {
add_meta_box( 
    'performer_info_box',
    __( 'Performer Info', 'myplugin_textdomain' ),
    'performer_info_box_content',
    'performer',
    'side',
    'high'
);

}

add_action( 'add_meta_boxes', 'performer_info_box' );

function performer_info_box_content( $post ) {
global $wpdb;
wp_nonce_field( 'performer_info_box_content', 'performer_info_box_content_nonce' );
echo '<div style="margin-top:10px;font-weight:bold">Owner</div>';
$user = get_user_by( 'id', $post->post_author );
$user_email = ($user) ? $user->user_email : '';
echo '<input id="performer_users" name="owner_email" value="'.$user_email.'">';

echo '<div style="margin-top:10px;font-weight:bold">Website</div>';
echo '<input type="text" id="performer_website" name="performer_website" placeholder="www.example.com" value="'.get_post_meta( $post->ID, 'performer_website', true ).'" />';

echo '<div style="margin-top:10px;font-weight:bold">Email</div>';
echo '<input type="text" id="performer_email" name="performer_email" placeholder="info@example.com" value="'.get_post_meta( $post->ID, 'performer_email', true ).'" />';

echo '<div style="margin-top:10px;font-weight:bold">Twitter</div>';
echo '<input type="text" id="performer_twitter" name="performer_twitter" placeholder="@example" value="'.get_post_meta( $post->ID, 'performer_twitter', true ).'" />';

echo '<div style="margin-top:10px;font-weight:bold">Facebook</div>';
echo '<input type="text" id="performer_facebook" name="performer_facebook" placeholder="www.facebook.com/example" value="'.get_post_meta( $post->ID, 'performer_facebook', true ).'" />';

echo '<div style="margin-top:10px;font-weight:bold">MySpace</div>';
echo '<input type="text" id="performer_myspace" name="performer_myspace" placeholder="www.example.com" value="'.get_post_meta( $post->ID, 'performer_myspace', true ).'" />';

}

add_action( 'save_post', 'performer_info_box_save' );

function performer_info_box_save( $post_id ) {

if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
return;

if ( !isset($_POST['performer_info_box_content_nonce']) || !wp_verify_nonce( $_POST['performer_info_box_content_nonce'], 'performer_info_box_content' ) )
return;

if ( !current_user_can( 'edit_post', $post_id ) ) return;

update_post_meta( $post_id, 'performer_website', $_POST['performer_website'] );
update_post_meta( $post_id, 'performer_email', $_POST['performer_email'] );
update_post_meta( $post_id, 'performer_twitter', $_POST['performer_twitter'] );
update_post_meta( $post_id, 'performer_facebook', $_POST['performer_facebook'] );
update_post_meta( $post_id, 'performer_myspace', $_POST['performer_myspace'] );
$user = get_user_by( 'email', $_POST['owner_email'] );
if ($user) {
    global $wpdb;
    $sql = "UPDATE ".$wpdb->base_prefix."posts SET post_author = %d WHERE ID = %d";
    $wpdb->query($wpdb->prepare($sql, $user->ID, $post_id));
}

}

add_filter('manage_posts_columns', 'performer_columns_head');
add_action('manage_posts_custom_column', 'performer_columns_content', 10, 2);

function performer_columns_head($defaults) {
global $post;
if ($post->post_type == 'performer') {
    $defaults['col_performer_owner_name'] = 'Owner';
    $defaults['col_performer_website'] = 'Website';
}
return $defaults;

}

function performer_columns_content($column_name, $post_ID) {
if ($column_name == 'col_performer_owner_name') {
    $post = get_post($post_ID); 
    if ($post) {
        $user = get_user_by( 'id', $post->post_author );
        if ($user)
            echo '<a href="mailto:'.$user->user_email.'">'.$user->display_name.'</a>';
    }
}
if ($column_name == 'col_performer_website') {
    $post = get_post($post_ID); 
    $www = $post->performer_website;
    if ($www) {
        if (strpos($www, 'http') === FALSE) $www = 'http://'.$www;
        echo '<a target="_blank" href="'.$www.'">'.$www.'</a>';
    }
}

}

0 个答案:

没有答案