Viewing 1 post (of 1 total)
  • Author
    Posts
  • #657108

    Sorry – couldn’t reopen the original thread! (https://kriesi.at/support/topic/shortcode-content-being-placed-out-of-dom-order/)

    The output works for HTML content, but I’m not sure how to use it to produce a loop through wp query.

    Example code:

    
    function test_shortcode() {
    
    $output = $featured_post_query;
    
    // WP_Query arguments
    $args = array (
    	'category_name'          => 'featured',
    );
    
    // The Query
    $featured_post_query = new WP_Query( $args );
    
    // The Loop
    if ( $featured_post_query->have_posts() ) {
    	while ( $featured_post_query->have_posts() ) {
    		$featured_post_query->the_post();
    		the_title();
    	}
    } else {
    	// no posts found
    }
    
    // Restore original Post Data
    wp_reset_postdata();
    
    return $output;
    }
    
    add_shortcode( 'shortcode', 'test_shortcode' );
    

    Thanks in advance!

    • This topic was modified 8 years, 4 months ago by ashloudon.
Viewing 1 post (of 1 total)
  • The topic ‘Shortcode Content Being Placed Out Of DOM Order’ is closed to new replies.