Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save viramgamijignesh/85f637840651ae2f6f8fe1d4c993a973 to your computer and use it in GitHub Desktop.
Save viramgamijignesh/85f637840651ae2f6f8fe1d4c993a973 to your computer and use it in GitHub Desktop.
$args = array(
'public' => true,
'_builtin' => false,
);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$postType = '';
$post_types = get_post_types( $args, $output, $operator ); // get all custom post type name
foreach ($post_types as $post_type) {
$postType[] = $post_type;
}
$taxonomies = get_taxonomies($args,$output,$operator); // get all custom post type taxonomy name
foreach ($taxonomies as $key => $value) :
$taxonomy = $value;
$terms = get_terms($taxonomy); // Get all terms of a taxonomy
if ( $terms && !is_wp_error( $terms ) ) :
foreach ( $terms as $term ) :
echo '<b>'.$term->name.'</b><br>';
$args = array(
'post_type' => $postType,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
'field' => 'slug',
'terms' => $term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) :
while($loop->have_posts()) : $loop->the_post();
echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br>';
endwhile;
endif;
endforeach;
endif;
endforeach;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment