Custom Fields
Re-Envisioned
Support General Display element based on 'post'

  • Creator
    Topic
  • #1306
    carassius
    Participant

    If I create a basic customer cpt
    name
    phone
    email
    address

    and then in another cpt use ‘type’ => ‘post’ to generate a drop down of names, how can I then filter the other components based on the selected name? Should I use the conditional extension, or is there a way to do this without?

    For example, if someone selects “john doe” I then want the other contact info displayed in input boxes. I hope that makes sense?

Viewing 10 replies - 1 through 10 (of 42 total)
  • Author
    Replies
  • #1308
    Anh Tran
    Keymaster

    Hi carassius,

    Yes, you’re right about using Conditional Logic extension. It’s made exactly for this purpose. Please try it and let us know if it works for you.

    Thanks.

    #1309
    carassius
    Participant

    Ok, will try and see if I can get it to work and come back if I have any questions 🙂

    Thanks
    Jon

    #1310
    carassius
    Participant

    Cant seem to get my head around how I can use the conditional logic.

    I can see how it makes different elements visible but that is now what I am after (unless I am thinking this wrong?)

    I want to look at the post selector

    $name = rwmb_meta( ‘p52_quote_name’, ‘type=text’ );

    and then take that and return the associated phone number to that contact
    $phone = rwmb_meta( ‘p52_contact_phone’, ‘type=text’ );

    So I could have something sort of like this (which is totally incorrect, I know)

    <?php

    function p52_register_quote_meta_boxes( $meta_boxes ) {

    $prefix = ‘p52_quote_’;
    $meta_boxes[] = array(
    ‘id’ => $prefix . ‘customer’,
    ‘title’ => ‘Customer Info’,
    ‘pages’ => ‘p52-quote’,
    ‘context’ => ‘normal’,
    ‘priority’ => ‘low’,

    ‘fields’ => array(

    array(
    ‘name’ => ‘Name’,
    ‘id’ => $prefix . ‘name’,
    ‘type’ => ‘post’,
    ‘post_type’ => ‘p52-contact’,
    ‘placeholder’ => ‘Select a Customer’,
    ‘columns’ => 6
    ),

    array(
    ‘name’ => ‘Phone’,
    ‘id’ => $prefix . ‘phone’,
    ‘post_type’ => ‘p52-contact’,
    ‘std’ => get_post_meta($post->ID, ‘p52_quote_phone’, true),
    ‘type’ => ‘text’,
    ‘columns’ => 6
    ),
    return $meta_boxes;
    }

    add_filter( ‘rwmb_meta_boxes’, ‘p52_register_quote_meta_boxes’ );

    #1311
    carassius
    Participant

    Warning: Invalid argument supplied for foreach() in C:\wamp\www\wordpress\wp-content\plugins\project52\plugins\meta-box-conditional-logic\inc\class-conditional-logic.php on line81

    #1320
    Tan Nguyen
    Participant

    Hi carassius,

    Thanks for using Conditional Logic

    As your requested, I’ve created a snippet with comments so you can see and use in your project. Basically, I use a ‘post’ field to display all customers and create a phone field which store customer phone and a set of phone fields equal to num of customers which has default value inside, when user post data, the visible phone field will replace default phone field. Have fun 🙂

    https://pastebin.com/6qC7CJwh

    #1324
    carassius
    Participant

    I get an error installing conditional logic

    #1325
    Tan Nguyen
    Participant

    Can you show me that error?

    #1326
    carassius
    Participant

    Warning: Invalid argument supplied for foreach() in C:\wamp\www\wordpress\wp-content\plugins\project52\plugins\meta-box-conditional-logic\inc\class-conditional-logic.php on line81

    this is how i am installing it
    if( !class_exists( ‘MB_Conditional_Logic’ ) ) {
    include( plugin_dir_path( __FILE__ ) . ‘/plugins/meta-box-conditional-logic/meta-box-conditional-logic.php’);
    }

    #1327
    carassius
    Participant

    also, if I do a var_dump ($customers) I dont get any of the metabox fields, so I must have something wrong with loading them into the loop when creating my cpt

    #1328
    carassius
    Participant

    Just redownloaded my core plugins and added that version, and the error is now gone, maybe a corrupt download

Viewing 10 replies - 1 through 10 (of 42 total)
  • The topic ‘Display element based on 'post'’ is closed to new replies.
grid gear info copy caret-up caret-down trash