1

I am running an affiliate shop with around 10k products and I am trying to build Landingpages for SEO/SEM purposes. Those pages should contain a title, some text and related products.

I would like to query the products by url slug. Is it possible to do something like this?

<?php $args = array(
    'post_type'      => 'product',
    'posts_per_page' => 12,
    'title'          => 'contains url slug' // add something like 
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
    while ( $loop->have_posts() ) : $loop->the_post();
        get_template_part( 'content', 'product' );
    endwhile;
}
else {
    _e( 'No products found' );
}
wp_reset_postdata();
?>

The product data is something that I get via remote APIs (from different merchants). Those responses don't contain any categories or taxonomies that I could use for this.

Alternative: Is there a way to display "search results" for the slug in the URl on this page?

1

You can use the name parameter in your arguments ex:

<?php 
$args = array(
  'post_type' => 'product',
  'posts_per_page' => 12,
  'name' => 'slug'
);

but this will only match the post with that same slug.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.