最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Get all properties of custom post type

programmeradmin2浏览0评论

Specifically, I'm trying to get get the 'Layout Group' of a given ThemeREX Custom Layout (which as I understand is just a Custom Post Type), but am also interested in seeing what other properties are available for that post.

I tried

print_r(get_post_meta(get_post(1738, 'ARRAY_A', 'display'),"",true));

but all that was returned was the number 1.

I'm guessing the meta is not what I'm looking for. Is there a way to iterate through all the custom properties that are registered with that post's CPT?

Specifically, I'm trying to get get the 'Layout Group' of a given ThemeREX Custom Layout (which as I understand is just a Custom Post Type), but am also interested in seeing what other properties are available for that post.

I tried

print_r(get_post_meta(get_post(1738, 'ARRAY_A', 'display'),"",true));

but all that was returned was the number 1.

I'm guessing the meta is not what I'm looking for. Is there a way to iterate through all the custom properties that are registered with that post's CPT?

Share Improve this question edited Nov 13, 2019 at 2:02 butlerblog 5,1213 gold badges28 silver badges44 bronze badges asked Nov 12, 2019 at 22:51 Daveh0Daveh0 1912 silver badges13 bronze badges 2
  • 1 Possible duplicate of Return all custom meta data for one custom post type – Jacob Peattie Commented Nov 12, 2019 at 23:09
  • (You want Marco's answer from the above question, not the accepted answer) – Jacob Peattie Commented Nov 12, 2019 at 23:09
Add a comment  | 

2 Answers 2

Reset to default 1

To get all the post_meta for a post, use:

$postmeta = get_post_meta(1738);
print_r($postmeta);

...which will give you a nested array of values that you can explore.

Once you've worked out what you need, you can get the individual setting / property / meta with:

$mySetting = get_post_meta(1738, "my-post-meta-key", true);

Take a look at the relevant entry on the WordPress Codex for a bit more detail.

Try:

print_r( get_post_type_object( ( get_post( 1738 ) )->post_type ) );

It should print an object of class WP_Post_Type.

发布评论

评论列表(0)

  1. 暂无评论