我正在使用WordPress搜索,但我在搜索结果上遇到了一个问题。
我的问题是,当我搜索我的产品时,我会得到输出,但它也会显示隐私政策结果。
Example
Displaying result code
<section id="primary" class="content-area mainSearch">
<main id="main" class="site-main">
<div class="equalPadding">
<div class="cp-seeWrapper">
<?php
if ( have_posts() ) :
get_search_form();//search form
?>
<div class="row">
<?php
while (have_posts()){ the_post();?>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12 ">
<div class="cp-shadow cp-seeSinglePostWrapper">
<?php the_post_thumbnail();?>
<div class="bg-white single-post-box">
<div class="d-flex cp-CategoryList">
<div class="seeDate"><?php echo get_the_date(\'F j, Y\'); ?></div>
<div class="cp_cat_list">
<?php $cat = get_the_category();?>
<a href="<?php echo esc_url( get_category_link( $cat[0]->term_id ) );?>"><?php echo $cat[0]->cat_name?></a><?php ?>
</div>
</div>
<div class="cp-b-content"><h2><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( \'echo=0\' ) ); ?>"><?php echo wp_trim_words(get_the_title(), 12, \'...\'); ?></a></h2></div>
<p><?php echo wp_trim_words(get_the_excerpt(), 25, \'...\'); ?></p>
</div>
</div>
</div>
<?php } ?>
<?php
//the_posts_navigation();
else :
get_template_part( \'template-parts/content\', \'none\' );
endif;
?>
</div>
</div>
</div>
</main><!-- #main -->
</section><!-- #primary -->
我只想显示我的帖子结果,但它也会显示页面。你能帮帮我吗?
Custom post type
// Register Custom Post Type testingpost
function create_testingpost_cpt() {
$labels = array(
\'name\' => _x( \'testingposts\', \'Post Type General Name\', \'textdomain\' ),
\'singular_name\' => _x( \'testingpost\', \'Post Type Singular Name\', \'textdomain\' ),
\'menu_name\' => _x( \'testingposts\', \'Admin Menu text\', \'textdomain\' ),
\'name_admin_bar\' => _x( \'testingpost\', \'Add New on Toolbar\', \'textdomain\' ),
\'archives\' => __( \'testingpost Archives\', \'textdomain\' ),
\'attributes\' => __( \'testingpost Attributes\', \'textdomain\' ),
\'parent_item_colon\' => __( \'Parent testingpost:\', \'textdomain\' ),
\'all_items\' => __( \'All testingposts\', \'textdomain\' ),
\'add_new_item\' => __( \'Add New testingpost\', \'textdomain\' ),
\'add_new\' => __( \'Add New\', \'textdomain\' ),
\'new_item\' => __( \'New testingpost\', \'textdomain\' ),
\'edit_item\' => __( \'Edit testingpost\', \'textdomain\' ),
\'update_item\' => __( \'Update testingpost\', \'textdomain\' ),
\'view_item\' => __( \'View testingpost\', \'textdomain\' ),
\'view_items\' => __( \'View testingposts\', \'textdomain\' ),
\'search_items\' => __( \'Search testingpost\', \'textdomain\' ),
\'not_found\' => __( \'Not found\', \'textdomain\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'textdomain\' ),
\'featured_image\' => __( \'Featured Image\', \'textdomain\' ),
\'set_featured_image\' => __( \'Set featured image\', \'textdomain\' ),
\'remove_featured_image\' => __( \'Remove featured image\', \'textdomain\' ),
\'use_featured_image\' => __( \'Use as featured image\', \'textdomain\' ),
\'insert_into_item\' => __( \'Insert into testingpost\', \'textdomain\' ),
\'uploaded_to_this_item\' => __( \'Uploaded to this testingpost\', \'textdomain\' ),
\'items_list\' => __( \'testingposts list\', \'textdomain\' ),
\'items_list_navigation\' => __( \'testingposts list navigation\', \'textdomain\' ),
\'filter_items_list\' => __( \'Filter testingposts list\', \'textdomain\' ),
);
$args = array(
\'label\' => __( \'testingpost\', \'textdomain\' ),
\'description\' => __( \'\', \'textdomain\' ),
\'labels\' => $labels,
\'menu_icon\' => \'\',
\'supports\' => array(\'title\', \'editor\', \'excerpt\', \'thumbnail\', \'author\'),
\'taxonomies\' => array(\'category\'),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'show_in_admin_bar\' => true,
\'show_in_nav_menus\' => true,
\'can_export\' => true,
\'has_archive\' => true,
\'hierarchical\' => false,
\'exclude_from_search\' => false,
\'show_in_rest\' => true,
\'publicly_queryable\' => true,
\'capability_type\' => \'post\',
);
register_post_type( \'testingpost\', $args );
}
add_action( \'init\', \'create_testingpost_cpt\', 0 );