Support

Account

Home Forums ACF PRO Dynamic creation of category selector Reply To: Dynamic creation of category selector

  • 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 🙁