Reputation: 2835
I'm working with custom post types. post type is created using types plugin. Custom post type name is partners
that has title , featured image and a custom field description this is how i am able to fetch image and title
<?php
$args=array('post_type' => 'partners');
$query= new WP_Query($args);
while ($query-> have_posts() ) : $query->the_post()?>
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-12">
<?php the_title;?>
<?php the_post_thumbnail( 'full', array( 'class' => 'innerimages')
);?>
</div>
<?php endwhile;?>
now how do i print that custom field content after title ?please help
Upvotes: 0
Views: 79
Reputation: 175
Please, pay attention to the documentation of "Types" plugin:
...Types custom fields use the standard WordPress post-meta table, making it cross-compatible with any theme or plugin....
So, it is possible to get the values of custom fields using the "get_post_meta" function:
get_post_meta ( int $post_id, string $key = '', bool $single = false )
If you know the name of custom field in the database, for example: description, it is possible to get its value into the loop, with the snippet of code:
get_post_meta ( get_the_ID(), 'description' )
Including the previous code in yours:
<?php
$args=array('post_type' => 'partners');
$query= new WP_Query($args);
while ($query-> have_posts() ) : $query->the_post()?>
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-12">
<?php the_title;?>
<?php the_post_thumbnail( 'full', array( 'class' => 'innerimages') );?>
<?php print get_post_meta ( get_the_ID(), 'description' ); ?>
</div>
<?php endwhile;?>
and that's all.
Best regards.
Upvotes: 1