List posts with slug title

by Smnc   Last Updated March 06, 2019 12:08 PM

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


Answers 1


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.

Antti Koskinen
Antti Koskinen
March 06, 2019 16:23 PM

Related Questions


Generate Random Slug When Adding Taxonomy

Updated February 15, 2018 01:08 AM


Rename a slug label

Updated July 25, 2019 10:08 AM


Exclude specific slug in 'get_terms'

Updated May 24, 2018 16:08 PM