I have this php code I am using to list all post (titles) with the taxonomy categories names, and its working fine however I will like to break it up and avoid using echo within the php code so that I can insert some more code. Here's the code I have that works --
<?php
$custom_terms = get_terms('videoscategory');
$other_custom_terms = get_terms('product_category');
foreach ($custom_terms as $custom_term) {
foreach ($other_custom_terms as $other_custom_term) {
wp_reset_query();
$args = array('post_type' => 'product', 'orderby' => 'title',
'order' => 'asc',
'tax_query' => array(
'relation' => 'AND',
'orderby' => 'title',
'order' => 'asc',
array(
'taxonomy' => 'product_category',
'field' => 'slug',
'terms' => $other_custom_term->slug,
'orderby' => 'title',
'order' => 'asc',
),
array(
'taxonomy' => 'videoscategory',
'field' => 'slug',
'terms' => $custom_term->slug,
'orderby' => 'title',
'order' => 'asc',
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h1 style="margin-top:10px;">'.$custom_term->name.'</h1>';
while($loop->have_posts()) : $loop->the_post();
echo '<h2><a href="'.get_permalink().'">'.get_the_title().'</a></h2>';
endwhile;
}
}
} ?>
And here's the code I have now that I have edited to try and accomplish what I would like to do --
<?php
$custom_terms = get_terms('videoscategory');
$other_custom_terms = get_terms('product_category');
foreach ($custom_terms as $custom_term) {
foreach ($other_custom_terms as $other_custom_term) {
wp_reset_query();
$args = array('post_type' => 'product', 'orderby' => 'title',
'order' => 'asc',
'tax_query' => array(
'relation' => 'AND',
'orderby' => 'title',
'order' => 'asc',
array(
'taxonomy' => 'product_category',
'field' => 'slug',
'terms' => $other_custom_term->slug,
'orderby' => 'title',
'order' => 'asc',
),
array(
'taxonomy' => 'videoscategory',
'field' => 'slug',
'terms' => $custom_term->slug,
'orderby' => 'title',
'order' => 'asc',
),
),
);
}
}
}
$loop = new WP_Query($args);
if($loop->have_posts()) : while($loop->have_posts()) : $loop->the_post(); ?>
<div class="box <?php echo $custom_term->slug; ?>">
<h1 style="font-weight:bold;font-size:18px;margin-top:10px;"><?php echo $custom_term->name ?></h1>
<h2><a href="<?php get_permalink(); ?>"><?php get_the_title(); ?></a></h2>
</div>
<?php endwhile; ?>
Basically what Im trying to do is assign the term name or slug as a class to my div so that I can use isotope filter to filter the list of posts by category. However I am receiving parse/syntax errors, and things are not working. What am I doing wrong? Any help is appreciated, thanks.
get_
return a string or array or object..., functions that start withthe_
echo out the result. Review your code with that in mind.