Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

wordpress - How to select WP page category?

I am trying to create a list with related wp pages at the end of each article. I am doing with with WP pages and not posts.

This is my code so far:

  $related = get_pages(array(
        'number'     => 5,
        'cat'        => '1',
        'sort_column' => 'date', 
        'sort_order' => 'desc',            
        'post_status'    => 'publish',
        'exclude_tree'   => get_the_ID(),
   ));

"cat" or "category" isn't doing anything. This code just lists pages from all categories instead of only category "1".

How can I limit it to only category 1?

I have categories for pages because I've added this to functions:

register_taxonomy_for_object_type('category', 'page');  
question from:https://stackoverflow.com/questions/65924349/how-to-select-wp-page-category

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...