Community Forums › Forums › Archived Forums › Design Tips and Tricks › How To Add Custom Fields to Custom Page Template
- This topic has 5 replies, 2 voices, and was last updated 11 years, 3 months ago by Michelle Waters.
-
AuthorPosts
-
July 14, 2013 at 11:23 pm #50739Michelle WatersParticipant
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.comJuly 15, 2013 at 3:41 am #50751Brad DaltonParticipantCould 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.
July 15, 2013 at 9:24 am #50791Michelle WatersParticipantI 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.
July 15, 2013 at 11:23 am #50806Brad DaltonParticipantNot 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.
July 15, 2013 at 11:49 am #50820Brad DaltonParticipantPlease try the second code snippet again and see if it works. I have changed it slightly.
July 15, 2013 at 12:21 pm #50833Michelle WatersParticipantI 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...
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.