😄get all posts ID from a category Emedic (ok)

https://wordpress.stackexchange.com/questions/71471/get-all-posts-id-from-a-category

Đọc thêm: https://wordpress-lionel.gitbook.io/wordpress/kiem-tra-bai-viet-co-thuoc-chuyen-muc-check-post-is-in-the-category-dakhoathienhoa.com.vn-ok#vi-du-2-khong-hieu-sao-thuc-hien-tren-phongkhamdakhoathienhoa.com.vn-khong-chinh-xacarrow-up-right

Ví dụ 1: Lấy 1 chuyên mục

Ví dụ 2: Lấy nhiều chuyên mục

Ask Questionarrow-up-rightAsked 10 years, 8 months agoModified 7 years, 9 months agoarrow-up-rightViewed 44k times7

Problem: I need to get an array of ID's of posts from a given category If the category have any posts. This is to be used on a plugin options page.

So far I have:

But I'm struggling with How do I gen an array containing just the ID of each post on that category.

Any Ideas ? Thanks

Sharearrow-up-rightImprove this questionarrow-up-rightFollowasked Nov 4, 2012 at 1:11user983248's user avatararrow-up-rightuser983248arrow-up-right1,35033 gold badges2020 silver badges3030 bronze badgesAdd a commentarrow-up-right

2 Answers

Sorted by: Highest score (default) Date modified (newest first) Date created (oldest first) 16

The thing to remember about get_posts is that is uses a WP_Query object internally. get_posts source:

Which, means, of course, that you can use any of the same arguments that WP_Query accepts. This includes parameters relating to fieldsarrow-up-right.

To get an array of just IDs, you'd need to do something like this:

Or you can wrap it up in a function for more flexibility.

Sharearrow-up-rightImprove this answerarrow-up-rightFollowanswered Nov 4, 2012 at 1:30chrisguitarguy's user avatararrow-up-rightchrisguitarguyarrow-up-right21.3k44 gold badges6060 silver badges9999 bronze badgesAdd a commentarrow-up-right0

Please refer to the following post: Get post ids from WP_Query?arrow-up-right

You should be using: wp_list_pluckarrow-up-right

Example:

Last updated