Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wordpress get taxonomy of a post

//Get all terms (names) of a taxonomy of a post
$term_obj_list = get_the_terms( $post->ID, 'taxonomy_name' ); ?>
Comment

wordpress get post taxonomy terms

//Get selected terms of a post by taxonomy
$selectedTerms = wp_get_post_terms(get_the_ID(),'TAXONOMY_NAME');
foreach($selectedTerms as $term){
	echo $term->name;
}
Comment

wordpress get terms by taxonomy

You need to pass an additional argument to get_terms(). The default is to hide
"empty" terms-- terms which are assigned to no posts.

$terms = get_terms([
    'taxonomy' => $taxonomy,
    'hide_empty' => false,
]);
Comment

get post by taxonomy

<?php
     $taxonomy = 'my_taxonomy'; // this is the name of the taxonomy
     $terms = get_terms($taxonomy);
     $args = array(
        'post_type' => 'post',
        'tax_query' => array(
                    array(
                        'taxonomy' => 'updates',
                        'field' => 'slug',
                        'terms' => wp_list_pluck($terms,'slug')
                    )
                )
        );

     $my_query = new WP_Query( $args );
     if($my_query->have_posts()) :
         while ($my_query->have_posts()) : $my_query->the_post();

              // do what you want to do with the queried posts

          endwhile;
     endif;
  ?>
Comment

wordpress get current taxonomy

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo $term->name; // will show the name
echo $term->slug; // will show the slug
Comment

get post by taxonomy

foreach ($myterms as $term) :

$args = array(
    'tax_query' => array(
        array(
            $term->slug
        )
    )
);

//  assigning variables to the loop
global $wp_query;
$wp_query = new WP_Query($args);

// starting loop
while ($wp_query->have_posts()) : $wp_query->the_post();

the_title();
blabla....

endwhile;

endforeach;
Comment

PREVIOUS NEXT
Code Example
Php :: console.log in php 
Php :: PHP strlen — Get string length 
Php :: strtoupper php 
Php :: laravel read origanl value before update 
Php :: CORSS oauth/token lavarel 
Php :: pathtophp in ubuntu lampp 
Php :: migration bool type eloquent orm 
Php :: php divide string into parts 
Php :: How to set a comment on table using Laravel Schema 
Php :: forelse laravel 
Php :: drupal 7 entity_metadata_wrapper bundle 
Php :: php find lowest value in associative array 
Php :: get params from url php 
Php :: laravel get class name 
Php :: str_replace php variable 
Php :: php redirect to page 
Php :: php number to month 
Php :: exclude methods in resource route laravel 
Php :: php base64 to image 
Php :: laravel string builder 
Php :: php format int to 9 digits with preceding zeroes 
Php :: php remove all parameter from url 
Php :: php convert multidimensional object to array 
Php :: php home url 
Php :: form submitting twice 
Php :: laravel generate unique token 
Php :: PHP Deprecated: Function create_function() 
Php :: woocommerce add custom field data to cart page 
Php :: laravel get url without domain in blade 
Php :: wordpress get child posts 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =