Tagged: Custom Post, fields
- This topic has 8 replies, 2 voices, and was last updated 5 years, 8 months ago by
rubenhak.
-
AuthorPosts
-
-
May 19, 2016 at 8:38 pm #6513
rubenhakMemberhi Everybody,
I’m very new to piklist. Trying to achieve a simple functionality. Need to have a custom post type with some fields: Text, checkbox, etc. Sounds simple but cant find the way to associate field types with custom post types. I looked through user guide, could define custom posts and fields, but could not make fields appear in the custom post. I’m missing something, but cant find what exactly.
I’d appreciate if you could share a simple example with me.
Thank you,
Ruben -
May 19, 2016 at 10:30 pm #6518
SteveKeymaster@rubenhak– Welcome to the Piklist community!
Try this tutorial it should help.
-
May 20, 2016 at 5:14 pm #6529
rubenhakMemberHi Steve,
Thanks for the response. I have managed to make this work. I have few followup questions.
1) I’ve managed to create a custom page and fields in a metabox. Can see and modify the values from editor admin screen. But when I open the custom page using permalink it shows up empty. How can I render some content based on the metabox field values?
2) How to get access to those metabox field values from REST APIs? I’m using WP REST API v2 to access the custom page: http://example.com/wp-json/wp/v2/movie/1234. But it does not include metabox data.
3) How are the metafield values stored? Could you share some internals.
Thank you,
Ruben -
May 20, 2016 at 5:21 pm #6530
SteveKeymaster@rubenhak– Glad you got it working!
Piklist stores data the standard WordPress way. This is one of the best features of Piklist… you can use standard WordPress functions to get and display your data. We don’t provide any helper functions because they are not needed.
1) By default most WordPress themes do not display post meta data. You view it, you need to pull it first. Use the standard WordPress function get_post_meta().
2) Piklist saves data normally. This tutorial should help you.
3) Nothing special here. The data is stored the same way WordPress would normally store it. Look in your database. The data is just there… nice and clean.
Let us know if you need any more help.
-
May 20, 2016 at 5:57 pm #6532
rubenhakMemberCool, you guys are great! I’ll look through this and might get back with few more questions.
-
May 20, 2016 at 7:31 pm #6533
rubenhakMemberhi Steve, This is me again 🙂
I could retrieve the values of meta fields. For trivial fields the data is self descriptive. Though there are some complications when it comes to groups. I have group 2 level grouping and parsing the contents does not seem trivial at all. Please see following example:
a: 4: { s: 8: "fieldA";a: 1: { i: 0;s: 12: "valueA"; } s: 14: "fieldB";a: 1: { i: 0;a: 1: { i: 0;s: 10: "valueB"; } } s: 10: "fieldC";a: 1: { i: 0;s: 3: "valueC"; } s: 10: "innerGroup";a: 1: { i: 0;a: 3: { s: 6: "fieldD";a: 2: { i: 0;s: 3: "valueD1";i: 1;s: 3: "valueD2"; } s: 20: "fieldE";a: 2: { i: 0;s: 3: "valueE1";i: 1;s: 7: "valueE2"; } s: 24: "fieldF";a: 1: { i: 0;a: 1: { i: 0;s: 5: "valueF"; } } } } }It does not seem obvious how to parse this data structure. Are there any helpers available that would return the data in a more consumable form?
Thanks,
Ruben -
May 20, 2016 at 8:24 pm #6535
rubenhakMemberI figured out that I can use “unserialize” to get nested arrays. But i still have a question. Data of the group is grouped by fields:
{ "fieldA": [ "group_1_fieldA_value", "group_2_fieldA_value", "group_3_fieldA_value", "group_4_fieldA_value" ], "fieldB": [ "group_1_fieldB_value", "group_2_fieldB_value", "group_3_fieldB_value", "group_4_fieldB_value" ], "fieldC": [ "group_1_fieldC_value", "group_2_fieldC_value", "group_3_fieldC_value", "group_4_fieldC_value" ], }It would be nice to have the date grouped by instances. Something like this:
{ "group1": { "fieldA" : "group_1_fieldA_value", "fieldB" : "group_1_fieldB_value", "fieldC" : "group_1_fieldD_value", "fieldD" : "group_1_fieldC_value", }, "group2": { "fieldA" : "group_2_fieldA_value", "fieldB" : "group_2_fieldB_value", "fieldC" : "group_2_fieldD_value", "fieldD" : "group_2_fieldC_value", }, "group3": { "fieldA" : "group_3_fieldA_value", "fieldB" : "group_3_fieldB_value", "fieldC" : "group_3_fieldD_value", "fieldD" : "group_3_fieldC_value", }, }I know this is a less of a deal if there is just one level of grouping, but when there are several nested groups that becomes much more complex to consume the data using APIs. By any chance do you guys have methods to do the transformation?
Thanks,
Ruben -
May 20, 2016 at 10:13 pm #6536
SteveKeymasterUpdate to the beta version. The arrays are cleaner.
Are you seeing the serialized array when you use
get_post_meta()? -
May 21, 2016 at 3:10 am #6537
rubenhakMemberI could not see difference in response in the beta version. Could you explain what was changed?
get_post_meta returns unserialized id the key(the second argument) is empty, but if the key is set, the data returned is unserialized.
-
-
AuthorPosts
- You must be logged in to reply to this topic.