Skip Navigation

[Resolved] Display Custom Post Fields as Dynamic Content

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 8 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by rebeccaR-3 8 years, 8 months ago.

Assisted by: Beda.

Author
Posts
#323740

I am trying to: Create a custom page template that will display a specific custom post type & it's desired fields as a table. Basically the table will have the post date and then 3 additional custom fields (type, description & downloads). The post type is already created. I just can't figure out how to pull the fields into a page template

hidden link

That is the page I am working on. Obviously only the headings are there, but the content would display underneath those headings accordingly.

<?php
				$args=array(
				'post_type' => 'sec-filing',
				'post_status' => 'publish',
				'posts_per_page' => -1,
				'caller_get_posts'=> 1
					);
				  ?>
				
			<table>
				<tr>
					<th>Date</th>
					<th>Form</th>
					<th>Description</th>
					<th>Downloads</th>
				</tr>

			</table>

This is what I have now. I know am missing the "while have posts" but every time I add that the page goes blank, so it's the incorrect code.

Any help is appreciated.

#323831

Thank you for contacting us here in the Support Forum

This is a query regarding basic PHP and WP API issues, and we usually do not support custom code which is not related to Toolset API or how-to's/issues in this very forum.

The Code you are using is not getting any custom fields (post_meta) to display.

It also just returns a array of posts, so you would need to first (after you get all your posts) construct a for-each loop, and in this loop, get the post_meta for each post (get your fields )

Then, you can display them however you like.

As a example, you could use something like this:

Get some content first

//get your posts
		$all_posts = get_posts(array(
			'numberposts'	=> -1,
			'post_type'		=> 'your_post_type')
		);

https://codex.wordpress.org/Template_Tags/get_posts

Then, foreach over those and get more details

if( $all_posts ){
			foreach( $all_posts as $single_post ){ 
//Example on how to get post_meta below:
$single_returned_post = get_post($single_post);
				$single_post_id = $single_returned_post->ID;
				$custom_field_one = get_post_meta($single_post_id, 'your_custom_field_slug', true/false);
//Etc
}
}

Then, you can echo all data you collected above with your preferred HTML

Also, not that you need to close PHP tags before you can proceed with HTML in a PHP file (just as you did), OR you can to use:
echo 'your HTML here';

Please consult the PHP DOC and WP API DOC in regard to gather all needed knowledge to this custom code here:
https://developer.wordpress.org/reference/functions/get_post_meta/
hidden link
hidden link
hidden link

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#323838

Thanks. Forgot to mark this as resolved last night.

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.