Few Developer Questions – Custom Fields

Home Forums HRM Few Developer Questions – Custom Fields

This topic contains 3 replies, has 2 voices, and was last updated by  abdul billoo 2 months, 3 weeks ago.

  • Author
    Posts
  • #43021

    abdul billoo
    Participant

    I would like to know the following.

    1. Get current employee meta fields especially the fields created using the paid custom fields.
    2. How to sort contacts with custom fields –

    erp_get_peoples(['type' => 'contact', 'number' => '-1', 'custom_field' => 'value' ])

    doesnt work.

  • #43053

    Mehedi Hasan
    Moderator

    Hello @Abdul

    You can pass the meta_key through [meta_query]. I'd recommend you to follow the codes on the file ..../wp-erp/includes/functions-people.php line number: 84.

    Following codes:

    if ( $meta_query ) {
                $sql['join'][] = "LEFT JOIN $pepmeta_tb as people_meta on people.id = people_meta.<code>erp_people_id</code>";
    
                $meta_key   = isset( $meta_query['meta_key'] ) ? $meta_query['meta_key'] : '';
                $meta_value = isset( $meta_query['meta_value'] ) ? $meta_query['meta_value'] : '';
                $compare    = isset( $meta_query['compare'] ) ? $meta_query['compare'] : '=';
    
                $sql['where'][] = "AND people_meta.meta_key='$meta_key' and people_meta.meta_value='$meta_value'";
            }

    Thanks

  • #43892

    abdul billoo
    Participant

    Your inital code says we can do it via arguments in erp\includes\functions-people.php

    
    $defaults = [
            'type'       => 'all',
            'number'     => 20,
            'offset'     => 0,
            'orderby'    => 'id',
            'order'      => 'DESC',
            'trashed'    => false,
            'meta_query' => [],
            'count'      => false,
            'life_stage' => '',
            'include'    => [],
            'exclude'    => [],
            's'          => '',
            'no_object'  => false
        ];
    

    Can u give an example with what i wish to achieve using $defaults or any example that is closer and works with multiple meta values?

    • This reply was modified 2 months, 4 weeks ago by  abdul billoo.
  • #44164

    abdul billoo
    Participant

    Any updates for this? I wouldn't want to use the SQL but instead use the query instead

You must be logged in to reply to this topic.