Answer the question
In order to leave comments, you need to log in
How to display posts whose title slug is similar to the category slug of other posts, playing with variables?
Good afternoon!
I have a single.php page with a similar structure inside.
$company_pname = wp_get_post_categories( $post->ID, array('fields' => 'all') );
foreach( $company_pname as $cat_comp ){
$cat_comp->slug;
}
$args = array( 'post_type' => 'post-pharmacy', 'posts_per_page' => 999999, 'name' => $cat_comp->slug );
$query_company_name = new WP_Query($args);
if ($query_company_name->have_posts()) {
while ($query_company_name->have_posts()) {
$query_company_name->the_post();?>
<h1><?php the_title(); ?></h1>
<?php }
}
wp_reset_postdata();
$cat_comp->slug
further, this variable, which stores only slugs, I use in the request in $args
namely, 'name' => $cat_comp->slug
and then I need it to display each post whose slugs are the title , specified in args. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question