Hi all,
For my website I’ve created a custom field where I want to select per page which post category will be displayed. Now I am trying to display the posts with the selected category (ACF field name = categorie) by inserting the ACF in the query_posts. But somehow I am not getting anything back. The code I use is:
<?php
$newscat = get_field("categorie");
query_posts('category_name=' . $newscat . '&showposts=5=ASC'); ?>
<?php if (have_posts()) : ?>
<div class="blok">
<div class="container2">
<div id="parallelogram">
<i class="icons fa fa-newspaper-o"></i><p class="coltekst">Team nieuws
</div>
<a href="#"><p class="text-align-right">nieuwsoverzicht >
</a>
</div>
<div class="activiteiten">
<ul class="list-group">
<?php while (have_posts()) : the_post(); ?>
<li class="list-group-item"><span><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></span></li>
<?php endwhile; ?>
</ul>
</div>
</div>
<?php wp_reset_query(); ?>
<?php else: ?>
<?php endif; ?>
What am I doing wrong here?
Hi @projectarthouse,
Could you please try to set the category name manually? something like:
query_posts('category_name=the-category-name&showposts=5=ASC'); ?>
If it returned correctly, could you please check the returned categorie field? You can check it like this:
var_dump(get_field("categorie"));
I hope this helps.