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

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

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 :: php factorial 
Php :: PHP Warning: Version warning: Imagick was compiled against Image Magick version 1654 but version 1650 is loaded. 
Php :: limit 1 1 in laravel query 
Php :: ucfirst meaning in php 
Php :: global laravel request() 
Php :: wp wordpress logout 
Php :: php move_uploaded_file 
Php :: laravellivewire is not defined 
Php :: PHP Max Input Vars 
Php :: wp get acf category in post 
Php :: $_GET["name"] 
Php :: woocommerce get product category name by id 
Php :: how to get random element from a given array via php faker in laravel 
Php :: In excel.php line 164: Class "MaatwebsiteExcelExcel" not found 
Php :: how to generate random string in laravel 
Php :: php shell script 
Php :: get header respnse code php curl 
Php :: php closecursor 
Php :: laravel route slug 
Php :: laravel websockets onmessage 
Php :: php get current date strtotime 
Php :: PHP Startup: Unable to load dynamic library 
Php :: php ternary operator 
Php :: append file in php 
Php :: how to get the number of days in the current month using carbon 
Php :: table has column laravel 
Php :: laravel dump query 
Php :: wp logs 
Php :: codeigniter redirect 
Php :: get woocommerce order details 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =