How can php be used to return data from custom fields in a post?
-
14-04-2021 - |
質問
How can php be used to the return data from a custom field in a post?
Any help would be greatly appreciated.
正しい解決策はありません
他のヒント
If you want to use php inside the Post Content editing interface, it will not work (for security reasons), unless you install a plugin that allows it.
If you mean that the php would be put in the template file, then you can use the functions the_meta();
(doc) and the more flexible get_post_meta($post_id, $key, $single);
.
I set something like this up by creating a template page and uploading via ftp. The gist of the coding using Advanced Custom Fields worked using the following in the editor:
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'post',
'category_name' => 'all-properties'
));
if( $posts ): ?>
<?php foreach( $posts as $post ):
setup_postdata( $post );
?>
<?php the_post_thumbnail( 'small' ); ?><br>
<b><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></b><br>
<?php the_field('short_description'); ?><br>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
Let me know if this is what you are looking for and if I can help with any further information. :)
所属していません wordpress.stackexchange