• Hi,

    Here is basically the code I’m using to build the connection between employees and companies. Then I need to retrieve employees in a company and filter by the meta used when creating the connection.

    Without filtering with the meta data, the correct records are retrieved.
    But, when I add the connected_meta to the search, I get duplicated records. The records see to be correct, I think?! But duplicate (2 for each record retrieved). Please see the code below.

    I hope someone can help me figure out what I’m doing wrong here. I been stuck at this for the last 3 days. Thanks in advance!

    //This is how I create the company-employee connection
    p2p_register_connection_type( array(
    ‘name’ => ‘company_to_employee’,
    ‘from’ => ‘company’,
    ‘to’ => ’employee’,
    ‘fields’ => array(
    ‘jobtitle’ => array(
    ‘title’ => ‘JobTitle’,
    ‘type’ => ‘select’,
    ‘values’ => array( ‘assistant-manager’, ‘manager’,’supervisor’, ‘regional-supervisor’ ),
    ‘default’ => ‘manager’
    ),
    ‘status’ => array(
    ‘title’ => ‘Status’,
    ‘type’ => ‘select’,
    ‘values’ => array( ‘pending’, ‘active’, ‘deactivated’, ‘deleted’),
    ‘default’ => ‘pending’
    ),
    ‘status_changed_by’ => array(
    ‘title’ => ‘Status Changed By’,
    ‘type’ => ‘text’
    ),
    ),
    ‘cardinality’ => ‘one-to-many’
    ) );

    //This is how I connect an employee to a company
    p2p_type( ‘company_to_employee’ )->connect( $company_id, $employee_id, array(
    ‘date’ => current_time(‘mysql’),
    ‘jobtitle’ => $term->slug,
    ‘status’ => $status
    ) );

    //This is how I’m trying to get specific employees in a company

    //get company object
    $company = get_post($company_id);

    //get company employees whose (job title is ‘supervisor’ OR ‘regional-supervisor’) AND (status is ‘active’ OR ‘pending’)
    $employees = get_users( array(
    ‘connected_type’ => ‘company_to_employee’,
    ‘connected_from’ => $company,
    ‘connected_meta’ => array( array(‘jobtitle’ => array(‘supervisor’, ‘regional-supervisor’)), array(‘status’ => array(‘verified’, ‘pending’) ),
    ‘suppress_filters’ => false,
    ‘nopaging’ => true
    ) );

    http://wordpress.org/extend/plugins/posts-to-posts/

Viewing 1 replies (of 1 total)
  • Thread Starter mikc03

    (@mikc03)

    I also tried this:

    ‘connected_meta’ => array( array(‘key’ => ‘jobtitle’, ‘value’=> array(‘supervisor’, ‘regional-supervisor’), ‘compare’ => ‘IN’ ), array(‘key’ => ‘status’, ‘value’=> array(‘verified’, ‘pending’), ‘compare’ => ‘IN’) ),

    still didn’t work

Viewing 1 replies (of 1 total)

The topic ‘Users connected to Custom post type — Connected meta issue’ is closed to new replies.