I'm new in wordpress. I'm trying load custom field of post from function.php. Below is code for function post grid layout function where I use custom field:
$args = array(
'post_type' => 'post',
'category_name' => 'category',
'posts_per_page' => -1,
'orderby' => 'ID',
'order' => 'ASC'
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
$c = 1;
$bpr = 5;
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class="member">
<div class="div-block-image">
<?php the_post_thumbnail(); ?>
</div>
<div class="div-block-29 w-clearfix">
<div class="text-block-21"><?php the_title(); ?></div>
<div class="text-block-22">subTitle</div>
<div class="text-block-23">Text...</div>
<a href="<?php the_permalink() ?>" class="more w-inline-block">
<div class="text-block-24">More</div>
</a>
<p><?php echo get_post_meta($post->ID, 'linkedin', true); ?></p> // custom-field
<p><?php echo get_post_meta($post->ID, 'bio', true); ?></p>
<a href="#" target="_blank" class="link-block w-inline-block">
<div class="biotxt">bio</div>
</a>
<a href="#" target="_blank" class="link-block w-inline-block">
<div class="text-block-20"></div>
</a>
</div>
</div>
<?
if( $c == $bpr ) {
echo '<div class="clear"></div>';
$c = 0;
}
$c++;
endwhile;
} else {
_e( '<h2>Oops!</h2>', 'rys' );
_e( '<p>Sorry, seems there are no post at the moment.</p>', 'rys' );
}
wp_reset_postdata();
I want to load this function from template page. All is loading normally except custom field:
<p><?php echo get_post_meta($post->ID, 'linkedin', true); ?></p>
If run function code from template page its running normal. Any ideas?