문제

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. :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top