Support » Plugin: Pods - Custom Content Types and Fields » Find function not working for User extension pod

  • Resolved danifola


    Hi, I have added a field called coach as an extension to user. I want to get all users that have a certain value for that field.

    Here’s my code:
    $pod_user = pods (‘user’);
    $params = array(
    ‘where’ => ‘coach.meta_value = ‘ . $id
    $pod_user->find( $params );

    And here’s the error on the log:
    [04-Jul-2019 14:29:21 UTC] Error Unknown column ‘coach.meta_value’ in ‘where clause’ de la base de datos de WordPress para la consulta SELECT

    FROM wpud_users AS t

    LEFT JOIN wpud_podsrel AS rel_coach ON
    rel_coach.field_id = 2196
    AND rel_coach.item_id = t.ID

    LEFT JOIN wpud_users AS coach ON
    coach.ID = rel_coach.related_item_id

    LEFT JOIN wpud_usermeta AS coach_meta_value ON
    coach_meta_value.meta_key = ‘meta_value’
    AND coach_meta_value.user_id = coach.ID

    WHERE ( ( coach.meta_value = 1 ) AND ( t.user_status = 0 ) )

    ORDER BY t.display_name, t.ID
    LIMIT 0, 15 realizada por require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/themes/hello-elementor-child/page-c.php’), Pods->find, PodsData->select, pods_query, PodsData::query, QM_DB->query

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


    Here’s an example of what you would use in each case for relationship lookups:

    * Relationship / File Field: related_field_name.field_name = $id
    * Relationship (Custom Simple): related_field_name.meta_value = $id

    If you are lookup by ID on a relationship field (not custom simple) then the field_name may be different based on the related pod:

    * Post types / Media: related_field_name.ID
    * Taxonomy: related_field_name.term_id
    * Users: related_field_name.ID
    * Comments: related_field_name.comment_ID

    Based on your feedback, this would be something like 'coach.ID = ' . $id

    One thing to be VERY careful about is that as you build this lookup, you should consider using the meta_query syntax which handles sanitization for you, or at the very least escape the value before you place it in the query. For and ID you should add (int) like this: 'coach.ID = ' . (int) $id

    For meta_query syntax, just reference this page which documents the array structure itself (for the 'meta_query' argument in WP_Query). Just pass that whole array into 'where' and it’ll be parsed by Pods:

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.