Hello,
what i need is to let my client select featured posts of categories in his site. For this I added a local field group in my plugin code.
array(
'key' => 'field_6172b1e27f165',
'label' => 'Featured cat posts',
'name' => 'featured_cat_posts',
'type' => 'post_object',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => array(
0 => 'post',
),
'taxonomy' => array(
0 => 'category:'.$slug,
),
This is real magic.
Testing with
$slug = "clients";
i’m able to select articles of may category “clients”.
This dynamic code fails
$catinfo = get_category( $tagID );
$slug = trim( $catinfo->slug );
even if the array is the same
'taxonomy' => array(
0 => 'category:clients',
),
Is there any wizard of oz function to get this working ?-))
I trie almost everything to be sure that this respects the format.
Cheers and thanks for all your ideas and helping
Christian
Do you need to select the category or posts within the category?
Hello @jarvis,
the aim is to select/edit a category, and then select the featured posts of that category. Maybe there is another way to do this ?
Cheers
Hmmm…
I’ve done it that you can select the category (using the taxonomy field > categories).
Then had a field to set the number of posts to return:
<?php
global $wp_query;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$post_category = get_field('post_category');
$number_of_posts = get_field('number_of_posts');
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $number_of_posts,
'paged' => $paged,
'cat' => $post_category,
'fields' => 'ids'
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php include( locate_template( 'includes/loop.php', false, false ) ); ?>
<?php endwhile;
endif; wp_reset_query();
Not sure how I’d then select the posts themselves. My only thought would be adding a tickbox to the posts themselves called ‘featured post’, you then amend the query to return only the posts in that category that have been ticked.
Seems a little long winded though 🙁
Hi,
thanks. This is indeed some nice wp_query. I’m afraid that this will not do the job for me. If cannot solve this strange behavior with the category selector, wil try something else. Option page, repeater for categories and selection of posts.
I have some great luck that i’m not too pressured by time.
Cheers and have a nice weekend
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.