MillerMedia
MillerMedia

Reputation: 3671

Adding Category Argument into an Array for WordPress Query

I'm new to customizing WordPress and am looking to query an array of posts within a certain category. I have a display that's showing an array of all posts from the site:

$arguments = array(
            'post_type' => 'post',
            'post_status' => 'publish',
            'paged' => $paged,
            'showposts' => $postcount
        );

Basically, I want to be able to show an array of all posts that are only in the category "Nutrition". I figured it's a 'category' argument that would be added into this array?

Upvotes: 0

Views: 379

Answers (2)

Rikesh
Rikesh

Reputation: 26421

Add category_name in your arguments.

$arguments = array(
        'post_type' => 'post',
        'post_status' => 'publish',
        'paged' => $paged,
        'showposts' => $postcount
        'category_name' = 'Nutrition'
    );

query_post($arguments);

For more details read this.

Upvotes: 1

Stephan
Stephan

Reputation: 43013

The argument is category_name not category

You can do this :

    $arguments = array(
        'post_type' => 'post',
        'post_status' => 'publish',
        'paged' => $paged,
        'showposts' => $postcount,
        'category_name' => 'Nutrition'
    );

Upvotes: 2

Related Questions