Getting custom fields to appear in template

Whew! I have figured out how to get the CPT to show up on my custom template in Genesis. I only have a title and custom fields, so currently, the title is showing up on the page, and I can view each individual post.

The problem is that I can't get the custom fields to show up on the page view or the single post view.

Since I am using the Genesis theme, I've also asked for their assistance here:

http://www.studiopress.com/forums/topic/how-to-add-custom-fields-to-custom-page-template/#post-50791

I am wondering if you can take a peek at our discussion there and see if there is anything we're missing from a Custompress perspective.

Thank you so much for your help!

  • Arnold
    • El Macho WP

    One problem I see is

    property="title | description | value"]

    The | means OR. You can use
    property="title"
    or
    property="description "
    or
    property="value"

    Depending on what you want to display.

    Also the template code you showed in the first post was already in <?php ?> tags so you wouldn't use them there.

  • TechGeekMinistries
    • Flash Drive

    I also found these error messages:

    Notice: Use of undefined constant single - assumed 'single' in /home/svillebc/public_html/wp-content/themes/outreach/functions.php on line 146

    Notice: Use of undefined constant clients - assumed 'clients' in /home/svillebc/public_html/wp-content/themes/outreach/functions.php on line 146

    Notice: Use of undefined constant php - assumed 'php' in /home/svillebc/public_html/wp-content/themes/outreach/functions.php on line 146

  • TechGeekMinistries
    • Flash Drive

    Awesome! Thank you so much. I really appreciate you.

    I also need to add several more custom fields from CustomPress. Can you show me how to modify the code I just put into functions.php?

    I thought adding additional echo statements would make the additional fields appear, but that doesn't seem to be the case:

    /** Add CustomPress custom fields to single-client.php file */
    function execute_shortcode_custom_post_type() {
     if( 'clients' == get_post_type() && is_single() ) {
        echo do_shortcode('[ct id="_ct_datepicker_51e310a9c8a48" property="value"]');
        echo do_shortcode('[ct id="_ct_text_51e310fa15f6f" property="value"]');
       }
    }
    
    add_action('genesis_header', 'execute_shortcode_custom_post_type');
    
    function custom_fields_shortcode() {
    if (is_page_template('single-clients.php') ) {
        echo do_shortcode('[ct id="_ct_datepicker_51e310a9c8a48" property="value"]');
        echo do_shortcode('[ct id="_ct_text_51e310fa15f6f" property="value"]');
       }
    }

    I am determined to learn how to do this. Thank you so much for your help!

  • Arnold
    • El Macho WP

    Well you're linking to 'genesis_header' which is outside the loop. I don't think the post has been picked yet. The output is being put in the page but the hook you used is buried behind the menu.

    Also the header background is black and the default text color is black. Blak on black doesn't show too well.

    I made the text white and moved it up to demonstrate.

    What are you trying to do?

  • TechGeekMinistries
    • Flash Drive

    I can see the date custom field, right above the title field. So I added the embed code for the name, but am not seeing that custom field added:

    http://tgmsandbox.com/blog/clients/john-doe/

    Technically, I'd like the title to appear first, then all my custom fields after it.

    Here is the code I modified in the functions. php file:

    /** Add CustomPress custom fields to single-client.php file */
    function execute_shortcode_custom_post_type() {
     if( 'clients' == get_post_type() && is_single() ) {
     	?>
     	<div style="position: absolute; top: 30px;color: #fff;">
        Date: <?php echo do_shortcode('[ct id="_ct_datepicker_51e310a9c8a48" property="value"]'); ?>
        Name: <?php echo do_shortcode('[ct id="_ct_text_51e310fa15f6f" property="value"]'); ?>
      </div>  
    
      <?php
       }
    }
    
    add_action('genesis_header', 'execute_shortcode_custom_post_type');
    
    function custom_fields_shortcode() {
    if (is_page_template('single-clients.php') ) {
        echo do_shortcode('[ct id="_ct_datepicker_51e310a9c8a48" property="value"]');
        echo do_shortcode('[ct id="_ct id="_ct_text_51e310fa15f6f" property="value"]');
       }
    }
  • TechGeekMinistries
    • Flash Drive

    I see the custom fields block and table wrap. Is the custom fields block calling all of my custom fields? If so, does that mean I can get rid of the two lines I added to call custom fields?

    Are all the changes you made in functions.php? Or did you need to make changes elsewhere?

    I'd like to understand what you so graciously did, but I'm a little flummoxed.

    Again, thank you so much for your help!

  • Arnold
    • El Macho WP

    Yes that one line does all the fields. Take a look at the ShortCodes tab in the CustomPress > Conent types to see how it works.

    You probably don't need the singles-clients.php since the date is in the custom block.

    You second function seems unnecessary as well.

  • TechGeekMinistries
    • Flash Drive

    I cut out the extra stuff you suggested I didn't need in the functions file. All the pertinent information is still in place, so that's awesome.

    I'm a little flummoxed through because the single client page is showing the title for both clients, with the correct custom fields for the page.

    See the screenshot below.

    How hard would it be to make the /clients page show just the names of the clients (entered in the title), while the /clients/client-name page shows just the one title and that client's custom fields?

    Or...

    Would it be easier to show all clients and their custom fields on one page?

    Again, thank you so much for your help!

  • TechGeekMinistries
    • Flash Drive

    I removed the following code:

    Date: <?php echo do_shortcode('[ct id="_ct_datepicker_51e310a9c8a48" property="value"]'); ?>
        Name: <?php echo do_shortcode('[ct id="_ct_text_51e310fa15f6f" property="value"]'); ?>

    I also removed the second function.

    In single-clients.php, I removed:

    echo do_shortcode('[ct id="_ct_datepicker_51e310a9c8a48" property="value"]');

    Then I added Jane Doe via Custompress.

  • TechGeekMinistries
    • Flash Drive

    Cool. That's working.

    One more question.

    In order to make any entry added to this CPT private, I assume I need to use the membership plugin?

    Is there a simpler way to do this? We will be manually adding users, who will only be able to add/edit their own entries in this CPT (nowhere else), and view all other client entries.

  • Arnold
    • El Macho WP

    When you say private, do you mean needs a password to get to it?

    MOst likely all you'll need is capabilities

    CustomPress > Content type > Post types > clients. Then in the capabilities section set the role your users will have to be able to edit and publish clients but not others clients.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.