List all posts from custom post type by taxonomy

admin2025-01-07  3

Having custom post types with taxonomies.

Lets say I have a custom post type "Products" with taxonomies "new", "old", "fashion".

Now I have a Nav where I can click on wordpress.private/products/new/ but I always get a 404 page and seems like it's not even calling index.php file.

How can I get all those posts ?

Having custom post types with taxonomies.

Lets say I have a custom post type "Products" with taxonomies "new", "old", "fashion".

Now I have a Nav where I can click on wordpress.private/products/new/ but I always get a 404 page and seems like it's not even calling index.php file.

How can I get all those posts ?

Share Improve this question asked Oct 20, 2014 at 8:17 carambacaramba 1,4162 gold badges15 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You could try this way.

Create a new page called say 'All products' and apply the following template to it.

Here is the code for that should be used in your template, just above the while loop.

   $type = 'products';
   $args=array(
  'post_type' => $type,
  'post_status' => 'publish',
  'posts_per_page' => -1,
  'caller_get_posts'=> 1

  query_posts($args);

A complete sample template will be like below.

<?php
/**
 * Template Name: Page of Products
 *
 * Selectable from a dropdown menu on the edit page screen.
 */
?>

<?php get_header(); ?>

        <div id="container">
            <div id="content">

<?php
$type = 'products';
$args=array(
  'post_type' => $type,
  'post_status' => 'publish',
  'posts_per_page' => -1,
  'caller_get_posts'=> 1


query_posts($args);

if( have_posts() ) {
  while (have_posts()) : the_post(); ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
  endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>
            </div><!-- #content -->
        </div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

It is not necessary that this is exact structure of your template. You may need to modify accordingly. But the logic is here.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736265167a1024.html

最新回复(0)