How To Add Custom Fields to Custom Page Template

Community Forums Forums Design Tips and Tricks How To Add Custom Fields to Custom Page Template

This topic is: not resolved

This topic contains 5 replies, has 2 voices, and was last updated by  Just Me 1 year, 3 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #50739

    Just Me
    Participant
    Post count: 23

    I have created a custom page template called single-clients.php. It is pulling in a Custom Post Type called Client, which I setup in Custompress. This all seems to be working fine.

    My problem is that I am not proficient enough in PHP to be able to pull in my custom field types.

    Can you help?

    This is what I have in my template:

    <?php
    /**
      * @author Tech Geek Ministries
     */
     
    /*
    Template Name: Clients Page
    */
    
    /**
     * This removes the loop.
     * If you want to include the static page title and content,
     * remove or comment out this code.
     */
    remove_action( 'genesis_loop', 'genesis_do_loop' );
    
    add_action( 'genesis_loop', 'tgm_custom_loop' );
    
    function tgm_custom_loop() {
     
    
                //WP Query Start
     
                $per_page = 9;
     
                $clients_args = array(
                    'post_type' => 'clients',
                    'posts_per_page' => $per_page,
                                    'paged' => get_query_var( 'paged' )
                );
                $clients = genesis_custom_loop( $clients_args );
    
    }
     
    /** Move Post Info */
    remove_action('genesis_before_post_content','genesis_post_info');
    remove_action('genesis_after_post_content','genesis_post_meta');
    
    genesis();

    And here is a php code for one of my custom fields:

    <?php echo do_shortcode('[ct id="_ct_datepicker_51e310a9c8a48" property="title | description | value"]'); ?>

    I’m not sure how to put the two of these together.


    http://www.tgmsandbox.com
    #50751

    braddalton
    Participant
    Post count: 10261

    Could you paste the PHP for your custom fields in Pastebin or Githib Gists and link to it from here please. Thanks

    You could do what is needed without using a custom page template and simply use your child themes functions.php file.

    I always test my code however in this case, i didn’t because i don’t have a custom post type setup for clients and don’t have a custom template named single-clients.php created.

    You can easily change the hook position where you want to display your date picker.


    #50791

    Just Me
    Participant
    Post count: 23

    I tried this code, but nothing showed up on my page. I checked both the clients page and a single post page with the client content, but the custom field did not appear.

    I also tried pasting in the code from Pastbin, but the forum software is stripping the HTML out.


    • This reply was modified 1 year, 3 months ago by  Just Me.
    • This reply was modified 1 year, 3 months ago by  Just Me.
    • This reply was modified 1 year, 3 months ago by  Just Me.
    • This reply was modified 1 year, 3 months ago by  Just Me.
    #50806

    braddalton
    Participant
    Post count: 10261

    Not sure what code you used to create the custom field. Did you use the native WordPress custom fields, code or a plugin to create the custom fields?

    The code snippets above are simply an example of how to execute shortcodes using the custom post the conditional and page template conditional. You wouldn’t need a shortcode for a custom field if you use the correct code to create it.


    #50820

    braddalton
    Participant
    Post count: 10261

    Please try the second code snippet again and see if it works. I have changed it slightly.


    #50833

    Just Me
    Participant
    Post count: 23

    I am using custompress to create my CPTs.

    I added the single quotes around single-clients.php, and changed property=”title | description | value” to property=”value” and my first custom field type appeared. Yeah!!!

    Now my second quandary: Getting the rest of my custom fields for this CPT to appear…


Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.