As per the Wordpress documentation WP_Query Category Parameters.
category_name
(string) – use category slug.
The argument's name category_name
is actually misleading, category_name
is referring to the category SLUG, NOT the actual category NAME.
<?php
$args = [
'posts_per_page' => 1,
'post_status' => 'publish',
'post_type' => 'mwp_interview',
];
$query = new WP_Query( $args );
if( $query->have_posts() ):
$i = 0;
while( $query->have_posts() ): $query->the_post();
$i++;
if ( $i > 1 )
echo "<hr>";
the_title( '<h1>', '</h1>' );
endwhile;
else:
echo 'No "interview" just yet!';
endif;
wp_reset_postdata(); ?>
<?php
$args = [
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => 'essays-in-discipleship', // ... must be set set to "Essays In Discipleship" category slug
'posts_per_page' => 1,
];
$query = new WP_Query( $args );
if( $query->have_posts() ):
$i = 0;
while( $query->have_posts() ): $query->the_post();
$i++;
if ( $i > 1 )
echo '<hr>';
the_title( '<h1>', '</h1>' );
endwhile;
else:
echo 'No "Essays In Discipleship" just yet!';
endif;
wp_reset_postdata(); ?>
<?php
$args = [
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => 'special-post', // ... must be set to "Special Post" category slug
'posts_per_page' => 1,
];
$query = new WP_Query( $args );
if( $query->have_posts() ):
$i = 0;
while( $query->have_posts() ): $query->the_post();
$i++;
if ( $i > 1 )
echo '<hr>';
the_title( '<h1>', '</h1>' );
endwhile;
else:
echo 'No "Special Post" just yet!';
endif;
wp_reset_postdata(); ?>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…