1

I have added category support for pages

in functions.php:

function add_categories_to_pages() {
    register_taxonomy_for_object_type( 'category', 'page' );
    }
    add_action( 'init', 'add_categories_to_pages' );

I created the category 'saloane', I have pages with category 'saloane' added

in home.php:

$saloane_q = new WP_Query ( array('post_type' => 'page', 'category' => 'saloane' ));
if ($saloane_q->have_posts()) :
    while ($saloane_q->have_posts()) : $saloane_q->the_post();
        echo '<div class="f3">';    
        the_post_thumbnail('hr_medium');
        echo '<h2>';
            the_title();
        echo '</h2>';
        the_excerpt();
        echo '</div>';
    endwhile;
endif;
wp_reset_postdata();
?>

there should be only the pages with category 'saloane' shown, but instead all the pages are shown

I also tried:

$saloane_q = new WP_Query ( array('post_type' => 'page', 'category' => 11 ));

$saloane_q = new WP_Query ( array('post_type' => 'page', 'cat' => 11 ));

the same result.

with:

$saloane_q = new WP_Query ( array('post_type' => 'page', 'category_name' => 'saloane' ));

does not display anithyng

if I use it without post_type like this:

$saloane_q = new WP_Query ( array('category' => 11 ));

$saloane_q = new WP_Query ( array('cat' => 11 ));

it displays the posts.

1 Answer 1

0

I just re created the category. Deleted the old category and created a new category with the same name, and now it`s ok.

The pages were imported with the native WordPress import-export plugin, from another wp installation, with the category as well (the category was automatically created when I imported the pages), maybe something went wrong at the import-export process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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