Forum Replies Created

Viewing 14 replies - 1 through 14 (of 14 total)
  • Check out the members plugin by Justin Tadlock for this behaviour.

    Thread Starter tomwhita

    (@tomwhita)

    Just bumping to see if the support thread is still being monitored…

    tomwhita

    (@tomwhita)

    Any update on this?

    Thread Starter tomwhita

    (@tomwhita)

    Can I hire you to help me populate the right value in my gravity forms function when adding associations? I just need this done and I can’t figure it out. Let me know.

    Thread Starter tomwhita

    (@tomwhita)

    I ended up just changing the association field to a plain text field that will store the ID of the foreman. Since the user won’t be accessing the wordpress admin, the fancy association UI wasn’t needed. I would’ve liked to have figured this out but I have to move on to other things.

    Thanks again for all your help.

    TW

    Thread Starter tomwhita

    (@tomwhita)

    I got it!!!!

    I used:

    $foreman_association = carbon_get_post_meta( $post->ID, 'foreman_association', 'association' ); $foreman = get_user_by('id', $foreman_association[0]['id']); echo esc_html($foreman->display_name);

    I’m still hung up on inserting association values though. I’m trying to insert a user association when I submit a form to create a new project. The gravity form has a drop down field with the display name of the foreman and a value of:

    "user:user:' . $User->ID . '"

    This doesn’t work at all. I can’t find any documentation for gravity forms about submitting values as arrays. Can you suggest anything else?

    Thread Starter tomwhita

    (@tomwhita)

    Once you have the ID, get_user_by($id) will work properly and retrieve the user object. Note: association data is returned as an array, so you would probably have to call $project_users[0][‘id’] in the get_user_by() call.

    I don’t undertand. Here is what I’ve tried. This doesn’t work:

    $foremanid = carbon_get_post_meta( $post->ID, 'foreman_association', 'association' ); $foreman = get_user_by( $foremanid[0]['id'] ); echo esc_html($foreman->display_name)

    Please help. I’m so close to being finished with this feature.

    Thanks

    TW

    Thread Starter tomwhita

    (@tomwhita)

    I really appreciate your patience with me. I’m trying to push my limits as a developer a little…

    The way I’ve been able to create an association when submitting a form is by sending the unserialize value. Like this:

    '"post:project:' . $post->ID . '"' But like I said, the association doesn’t show up in the Admin panel. Though i’m able to see associated data on my page template if I pull it using:

    $args = array(
                        'post_type' => array('document'),
                        'post_status' => array('publish'),
                        'meta_query' => array(
                                  array(
                                           'key' => '_doc_project_association',
                                           'compare' => 'LIKE',
                                           'value' => '"post:project:'.$post->ID.'"',
                                                                 ),
                                                             ),
                                        );
                      $docs = get_posts($args);

    When I try to use:

    array( 'post:project:$post->ID' ) to set the field variable, it does not work.

    What am I doing wrong?

    Also, can you go one step further in the get_user_by() reference. For example, would it be get_user_by(project_users->ID)?

    Thread Starter tomwhita

    (@tomwhita)

    Thanks. I’m having lots of fun with this project so far ??

    I have successfully managed to insert an association value using a gravity form but the association is not shown in the carbon fields UI in the admin. Do you know why this might happen?

    Also, how do I now retrieve data from an association field in a usable way? For example, I have associated users with the custom post type “Project”. How can I show the display name of the user on my page template?

    TW

    Thread Starter tomwhita

    (@tomwhita)

    Thanks again. I actually added the documents before changing the data setting and so they were still storing the ID. I updated them and everything works.

    I really appreciate your help.

    I have the same problem….trying to use gravity forms and + CPT plugin to allow front end creation of a CPT with hidden meta fields. Did you find a resolution?

    Thread Starter tomwhita

    (@tomwhita)

    This is great. Thank you so much.

    Just one final question…How do I echo the url of the file in ‘doc_file’?

    I’ve already changed the field declaration to:

    Field::make('file', 'doc_file', 'File (PDF)')
                ->set_value_type (url),

    And I’m attempting to call it via:

    $docs = get_posts($args);
       foreach ($docs as $post) :
       $doclink = carbon_get_post_meta ($post->ID,'doc_file');
       setup_postdata($post);
       ?>
    
    <div class="mdl-list__item">
    <span class="mdl-list__item-primary-content"><i class="material-icons mdl-list__item-avatar ion-document-text"></i>
     <span><a href=<?php echo $doclink; ?> target="_blank">
    <?php the_title(); ?></a></span>
    </span>
    </div>

    It outputs a link but its the link to the “project” post in the loop. I want to link to the file that associated with the project.

    Thread Starter tomwhita

    (@tomwhita)

    Container::make('post_meta', __('Document Information'))
            ->show_on_post_type('document')
            ->add_fields(array(
                Field::make('text', 'doc_description', 'Description'),
                Field::make('file', 'doc_file', 'File (PDF)'),
                Field::make('association', 'doc_project_association', 'Assign To Project')
                ->set_types(array(
                array(
                'type' => 'post',
                'post_type' => 'project',
                ),
                )),
            ));
    Thread Starter tomwhita

    (@tomwhita)

    Thanks. This makes sense. I wasn’t able to find the answer in your docs. Was it in there? Perhaps I missed it.

    I changed the code to your preferred solution and it works. I also added an esc_html. Below is the complete solution for showing a field value within a loop in case anyone is interested:

    Assumes you’ve already fetched the posts:

    <?php $yourfieldvariable = carbon_get_post_meta($post->ID, 'your_field_key'); echo esc_html( $yourfieldvariable ); ?>

Viewing 14 replies - 1 through 14 (of 14 total)