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:
- Samsung ->(slug / category)
- Galaxy note 5
- Galaxy note 5
- 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:
- Samsung ->(slug / category)
- Galaxy note 5
- Galaxy note 5
- Apple ->(slug / category)
- Iphone7
- Iphone8
- 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
1 Answer
Reset to default 0If 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.