Home › Forums › Backend Issues (wp-admin) › Post Object at random › Reply To: Post Object at random
Only using
<php?
function imwz_rand_posts() {
$args = array(
'post_type' => 'molecule',
'orderby' => 'rand',
'posts_per_page' => 1,
);
$the_query = new WP_Query( $args );
$string = '';
if ( $the_query->have_posts() ) {
$string .= '<div>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$string .= '<h3><a href="'. get_permalink() .'">'. get_the_title() .'</a></h3>';
$string .= '<p>' . the_excerpt() . '</p>';
}
$string .= '</div>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
$string .= 'no posts found';
}
return $string;
}
// [imwz-random-posts] shortcode
add_shortcode('imwz-random-posts','imwz_rand_posts');
add_filter('widget_text', 'do_shortcode');
the paragraph part loads above all other data/blocks and not below the title inside the same shortcode block. Any ideas why?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.