i have create custom post type for show plans and i want to show post according to category. i am using below code in functions.php for creating custom post type for plans.

add_action('init', 'create_post_types');
function create_post_types() {
    register_post_type( 'numbers_plan',
    array(
        'labels' => array(
        'name' => __( 'Numbers plan' ),
        'singular_name' => __( 'Numbers plan' )
    ),
    'public' => true,
    'has_archive' => true,
    'rewrite' => array('slug' => 'Numbers plan'),
     )
);

// Add new taxonomy(like categories)
$labels = array(
    'name'              => _x( 'PlanCat', 'numbers_plan', 'textdomain' ),
    'singular_name'     => _x( 'PlanCat', 'numbers_plan', 'textdomain' ),
    'search_items'      => __( 'Search PlanCat', 'numbers_plan' ),
    'all_items'         => __( 'All PlanCat', 'numbers_plan' ),
    'parent_item'       => __( 'Parent PlanCat', 'numbers_plan' ),
    'parent_item_colon' => __( 'Parent PlanCat:', 'numbers_plan' ),
    'edit_item'         => __( 'Edit PlanCat', 'numbers_plan' ),
    'update_item'       => __( 'Update PlanCat', 'numbers_plan' ),
    'add_new_item'      => __( 'Add New PlanCat', 'numbers_plan' ),
    'new_item_name'     => __( 'New PlanCat Name', 'numbers_plan' ),
    'menu_name'         => __( 'PlanCat', 'numbers_plan' ),
);

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'numbers_plan' ),
);

register_taxonomy( 'numbers_plans', array( 'numbers_plan' ), $args );
}

for show plans i have create plan.php page with blow code.

<?php
    $plan_group = get_terms( 'numbers_plans' );
?>

<?php
foreach ( $plan_group as $plan_group_term ) {
$plan_group_query = new WP_Query( array(
    'post_type' => 'numbers_plan',
    'tax_query' => array(
        array(
            'taxonomy' => 'numbers_plans',
            'field' => 'slug',
            'terms' => array( $plan_group_term->slug ),
            'operator' => 'IN'
        )
    )
));
?>
<h2><?php echo $plan_group_term->name; ?></h2>
<ul>
<?php
if ( $plan_group_query->have_posts() ) : while ( $plan_group_query->have_posts() ) : $plan_group_query->the_post(); ?>
    <div>
        <div><?php echo the_title(); ?></div>
        <div><?php the_field('plan_minutes'); ?></div>
        <div><?php the_field('monthly_cost'); ?></div>
        <div><?php the_field('cost_of_additional_minutes'); ?></div>
        <?php echo do_shortcode("[ARForms_popup id=103 desc='Buy Now' type='link' height='540' width='800']"); ?>
        <br/>
    </div>
<?php endwhile; endif; ?>
</ul>
<?php
// Reset things, for good measure
$plan_group_query = null;
wp_reset_postdata();
}
?>

it is showing all categories posts but i want to show only one category and it’s post. please tell me how can i do this.

Read more here: How to show custom post type posts according to category in wordpress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: