Answer the question
In order to leave comments, you need to log in
How to display wordpress posts that have two required custom fields, given the category?
The task is to display on the page of the wordpress heading the posts belonging to this heading, but with a breakdown into subtopics (as an example, there is a heading for teapots, I would like to break the heading itself into electric, gas, etc., there are arbitrary fields).
I can't attach a category, one category template is used for several categories, so the code must be universal, just substituting the category ID is not an option, it is necessary that the ID be calculated depending on the category.
Actually, a piece of code.
<?php
function idCat() {
if (is_category()) :
$identifikator_rubriki = get_query_var('cat');
endif;
return $identifikator_rubriki;
}
$args = array('meta_query' => array(array('key' => 'ключ произвольного поля', 'value' => 'значение произвольного поля',), array('key' => 'ключ произвольного поля-2', 'value' => 'значение произвольного поля-2',)), 'showposts' => '3', 'cat' => 'cat');
$news = new WP_query(); $news->query($args); ?>
<?php while ($news->have_posts()) : $news->the_post(); ?>
<div class="entry-thumb">
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
</div>
<?php endwhile; ?>
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