get category post in wordpress
echo '<p>'. get_the_category( $id )[0]->name .'</p>';
get category post in wordpress
echo '<p>'. get_the_category( $id )[0]->name .'</p>';
wordpress display post categories
<?php the_terms( $post->ID, 'topics', 'Topics: ', ', ', ' ' ); ?>
get primary category of post wordpress
This is not a native wordpress feature, but a feature of Yoast SEO (see here).
You can check for primary status the following way:
<?php
$term_list = wp_get_post_terms($post->ID, 'category', ['fields' => 'all']);
foreach($term_list as $term) {
if( get_post_meta($post->ID, '_yoast_wpseo_primary_category',true) == $term->term_id ) {
// this is a primary category
}
}
?>
If you are using custom taxonomies, use the meta_key
_yoast_wpseo_primary_CUSTOM_TAXONOMY
instead
Get wordpress posts by category name..!
<?php query_posts('category_name=CATEGORYNAME&showposts=5');
while (have_posts()) : the_post(); ?>
the_title(); // To display the title of all posts that have category name selected
the_content(); // To display the content of all posts that have category name selected
<?php endwhile; ?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us