Andy
Andy

Reputation: 551

Custom post loop with the 'posts_per_page' using the value of a custom field

Currently, I have a custom loop with the posts_per_page set to 5. However, I would like the posts_per_page to based on the value of a custom field in a specific 'Page'.

Is this possible?

Thanks

Upvotes: 0

Views: 77

Answers (1)

Haris
Haris

Reputation: 126

$post_id = get_the_ID();
    $key = 'custom_field_count';
    $post_count = get_post_meta($post_id, $key, true);
    $args = array(
        'posts_per_page' => $post_count,
    );
    query_posts($args);

Upvotes: 1

Related Questions