Support

Account

Home Forums Add-ons Repeater Field Populate Repeater Field with the number of posts per year

Helping

Populate Repeater Field with the number of posts per year

  • Hi, would it be possible to automatically create a new repeater row each year and then include the number of posts there were that year? Ideally pull the date for the posts from an ACF date field. I currently use the below snippet to count my total posts, hopefully this could be a starting point.

    $query = new WP_Query( array( 'meta_key' => 'status', 'meta_value' => '1', 'post_type' => 'project',) );
    
    $total_active_projects = $query->found_posts; //total active projects
  • You could do this by doing a query based on the date field, there are examples of this available. Then if you have a repeater somewhere, like on an options page, you can add rows to that repeater.

    But this sounds a little complicated to me to track how many posts there are per year. I would more than likely create a WP options value that contains an array and track how many posts are created for each year as they are created or updated. If I need to do this retroactively then I’d find a way to get and populate this list and then start adding to it.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.