create custom shortcode wp and put php code in
Question
i use ACF plugin and i want put this query in shortcode. but i have a problem.
this is edited and ture:
add_shortcode('pishnahadi' , 'kn_inline_related');
global $post;
function kn_inline_related( $atts ) {
$html= '';
$posts = get_field('pishnahadi', false, false);
$loop = new WP_Query(array('post_type' => 'news', 'posts_per_page' => 3, 'post__in' => $posts, 'post_status' => 'publish', 'orderby' => 'post__in', 'order' => 'ASC' ));
if($loop->have_posts()) {
$html .= '<div class="rel-posts">';
while ($loop->have_posts()) : $loop->the_post();
$html .= '<div class="related-post">';
$html .= '<h3><a href="' . get_permalink() . '">' . the_title( '', '', false ) . '</a></h3>';
$html .= '</div>';
endwhile;
$html .= '</div>';
} wp_reset_query();
return $html;
}
0
advanced-custom-fields, shortcode, wp-query
3 years
2020-04-05T04:50:50-05:00
2020-04-05T04:50:50-05:00 0 Answers
78 views
0
Leave an answer