custom taxonomy - List posts with slug title

admin2025-06-02  1

The code is for single-product.php. I can list all products on page but I want to list all posts with slug titles.

<?php
$args= array(
    'post_type'      => 'products',
    'order_by'       => 'date',
    'posts_per_page' => -1,
    'post__not_in'   => array( get_the_ID() ),
);

$wp_query = new WP_Query( $args );

while( $wp_query->have_posts() ) {
    $wp_query->the_post();
    echo '<a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
}

Example:

  1. Samsung ->(slug / category)
    • Galaxy note 5
    • Galaxy note 5
  2. Apple ->(slug / category)
    • Iphone7
    • Iphone8

The code is for single-product.php. I can list all products on page but I want to list all posts with slug titles.

<?php
$args= array(
    'post_type'      => 'products',
    'order_by'       => 'date',
    'posts_per_page' => -1,
    'post__not_in'   => array( get_the_ID() ),
);

$wp_query = new WP_Query( $args );

while( $wp_query->have_posts() ) {
    $wp_query->the_post();
    echo '<a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
}

Example:

  1. Samsung ->(slug / category)
    • Galaxy note 5
    • Galaxy note 5
  2. Apple ->(slug / category)
    • Iphone7
    • Iphone8
Share Improve this question edited Mar 6, 2019 at 11:35 Max Yudin 6,3982 gold badges26 silver badges36 bronze badges asked Mar 6, 2019 at 11:26 SmncSmnc 134 bronze badges 2
  • What is 'slug title'? – Max Yudin Commented Mar 6, 2019 at 11:38
  • i have 3 slugs ( samsung, iphone, lg,....) more slugs will create later.... – Smnc Commented Mar 6, 2019 at 11:50
Add a comment  | 

1 Answer 1

Reset to default 0

If by "slug title" you mean a taxonomy (e.g. product category), then have a look at the code posted on the accepted answer on Display All Products by Category with WooCommerce It should give you an idea (or even the complete solution) how to get your posts listed.

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

最新回复(0)