WordPress.org

Support

Support » Plugins and Hacks » [Resolved] How to insert value of relationship field into database

[Resolved] How to insert value of relationship field into database

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Scott Kingsley Clark

    @sc0ttkclark

    wp_podsrel stores all relationships for Pods. If a Pod object is meta-capable for storage (Post Types, Users, Comments) it stores a ‘ghost’ copy of that relationship in the corresponding meta table so that other configurations can access the relationships and traversals (Pods Tableless mode).

    The only fields you need to fill out in wp_podsrel for relationships / files are:

    • pod_id
    • field_id
    • item_id
    • related_item_id

    You can get the Pod ID from the pod editor URL &action=edit&id=X

    You can get the Field ID from the field manager, hovering over the field will reveal it next to the field label.

    Item ID is the item you are relating from, and Related Item ID is the item you are relating to.

    Thanks, Scott, but does it also apply to table based Pods Type. I just want the value of relationship fields can be inserted into the same table as common fields such as a text field.

    Plugin Author Scott Kingsley Clark

    @sc0ttkclark

    We do not yet have an option for relationship values to be stored in the database for Advanced Content Types. We are working on adding this feature, it may make it into the next release of Pods 2.3.

    Relationships set to Custom Simple (custom defined) values will be saved in the database table, so that may be useful if you want to put this together on your own.

    More information on how to work with Custom Simple relationships and override the values: http://stackoverflow.com/questions/14259179/how-to-change-output-of-a-certain-pods-field

    You mentioned “for Advanced Content Types”, but I meant the content type is “custom post type” but the storage type is “table based” when adding new types. Is it the same as “Advanced Content Types” or similar to meta-capable for storage that you early talk about?

    If it is, I will look forward to Pods 2.3 but is there any way which can solve it for the time being. I found an article http://podsframework.org/forums/topic/relationship-fields-not-in-mysql-database/, however, it seems to mean an early version of PODs, because I can’t find the “pods/ui/input_fields.php”. So any way for current version?

    Plugin Author Scott Kingsley Clark

    @sc0ttkclark

    Yes, it’s the same, if it’s set to table-based storage.

    The only way to solve it in Pods 2.x is using this filter as previously sent here:

    http://stackoverflow.com/questions/14259179/how-to-change-output-of-a-certain-pods-field

    You can use a Simple Custom Defined relationship and the filter above combined to store the data as you wish in the Database table itself.

    My php knowledge is limited.
    1. Do you mean that I should also use codes below?(Certainly, I know to modify the parameters)
    2. If so, where should I put this code? I mean which file under which path should I insert this code into?

    function pods_teacher_pick_data($data, $name, $value, $options, $pod, $id){
    if ($name == “pods_field_teachers”) {
    foreach ($data as $id => &$value) {
    $p = pods(‘teacher’, $id);
    $name = $p->display(‘name’);
    $city = $p->display(‘profile.city.name’);
    $value = $name . ‘ – ‘ . $city;
    }
    }
    return $data;
    }

    add_filter(‘pods_field_pick_data’, ‘pods_teacher_pick_data’, 1, 6);

    For example, I have two PODs types “Customer” and “CustomerContact”, both of which are Post types but table based.

    One fields in “Customer” type, “customer_name”, a text field;
    Two fields in “CustomerContact” Type, “customer_name_1”, a relationship field and “customer_contact”, a text field.

    The relationship field “customer_name_1” gets value from the text field “customer_name”. Now, the values of “customer_name_1” are not stored into the database table “wp_pods_CustomerContact”.

    Can you give me a complete code on how to insert the value of “customer_name_1” into the table of “wp_pods_CustomerContact” like a text field? And tell me where I should put this code?

    Thanks in advance

    Plugin Author Scott Kingsley Clark

    @sc0ttkclark

    Unfortunately, what you’re trying to do require prerequisites of PHP knowledge, and that’s something I’m unable to help you with. I’ve provided all of the references for you to do the custom code you’re wanting, but I’m unable to code it all for you.

    Is it possible to modify the code a bit which you gave Mert Nuhoglu to satisfy my need? And can you let me know at least where I should put this code? In which file? And under which path? Thanks

    function pods_teacher_pick_data($data, $name, $value, $options, $pod, $id){
    if ($name == "pods_field_teachers") {
    foreach ($data as $id => &$value) {
    $p = pods('teacher', $id);
    $name = $p->display('name');
    $city = $p->display('profile.city.name');
    $value = $name . ' - ' . $city;
    }
    }
    return $data;
    }
    
    add_filter('pods_field_pick_data', 'pods_teacher_pick_data', 1, 6);

    [Please post code snippets between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Hi, Scott, I read the article of http://stackoverflow.com/questions/14259179/how-to-change-output-of-a-certain-pods-field but think it may not be what I need.

    In Pods relationship field “Additional field options”, there is “Display Field in Selection List”. I just want the value of this “Display Field in Selection List” which I defined can be saved in the same table of database. I don’t know whether it can be achieved for Pods 2.0. I found nothing is saved in the table if it is a relationship field.

    Besides, I found this link but it can’t be visited now. Can you tell me what it is about and whether it is possible to use input helper to solve this problem for Pods 2.0?
    Please post the feature request at the following URL, it’s not possible built-in yet, but you can use an input helper to fool the form into treating the field as a relationship but storing it in a single line text field.
    https://github.com/sc0ttkclark/pods/issues/new

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Resolved] How to insert value of relationship field into database’ is closed to new replies.