Viewing 8 reply threads
  • Author
    Posts
    • #6513
      rubenhak
      Member

      hi 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

    • #6518
      Steve
      Keymaster

      @rubenhak– Welcome to the Piklist community!

      Try this tutorial it should help.

    • #6529
      rubenhak
      Member

      Hi 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

    • #6530
      Steve
      Keymaster

      @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.

    • #6532
      rubenhak
      Member

      Cool, you guys are great! I’ll look through this and might get back with few more questions.

    • #6533
      rubenhak
      Member

      hi 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

    • #6535
      rubenhak
      Member

      I 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

    • #6536
      Steve
      Keymaster

      Update to the beta version. The arrays are cleaner.

      Are you seeing the serialized array when you use get_post_meta()?

    • #6537
      rubenhak
      Member

      I 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.

Viewing 8 reply threads
  • You must be logged in to reply to this topic.