I have two blog categories that I want to display separately on the same page. In other words, one section will contain category 1 and the second section with contain category 2. Does anyone know how I can achieve this?


To achieve this I would recommend using the WP_Query class.

When using this approach, you are able to specify the parameters to search for posts (or categories) by.

For your particular question you should look at the Category Parameters. To target the categories you are looking for, you could do so by using their ID or their slug with the appropriate parameter label.

For example:

// WP_Query arguments
$args = array(
    'category_name'          => 'category-1',

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        // do something
} else {
    // no posts found

In the section where '// do something'' appears, is where you define what should be printed to the page.

There are useful websites you can use that generate this code for you - one such is GenerateWP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.