Answers for "wordpress post category"

PHP
1

get category post in wordpress

echo '<p>'. get_the_category( $id )[0]->name .'</p>';
Posted by: Guest on October-18-2021
0

wordpress display post categories

<?php the_terms( $post->ID, 'topics', 'Topics: ', ', ', ' ' ); ?>
Posted by: Guest on November-27-2020
0

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
Posted by: Guest on March-17-2021
0

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; ?>
Posted by: Guest on May-13-2021

Code answers related to "wordpress post category"

Browse Popular Code Answers by Language