The result of a shortcode appear BEFORE page content

I have a page, with a shortcode that get all the post from a categorie and put after the content of the page. For no apparent reason, the result of a WP_Query() in the shortcode APPEAR ALWAYS at the top of the page. If i put the shortcode a the top OR at the bottom, the post (3 of them) appear before the content of the page…

on that one, i have NO IDEA why… shortcode is at the en of the page


after the comment i post the code the ECHO… this is the problem ?.. i to solve it ?

//Add a ShorCode to get a page/post content
add_shortcode ('post_cat2','get_post_cat2');
   function get_post_cat2 ($att) {

       $mypost = array();

       $args = array( 'category' => 36 );
       $myposts = get_posts( $args );

       foreach( $myposts as $post ) :   setup_postdata($post);
       $mypost .= the_title();
       endforeach;
       return $mypost;

   }

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

codex the_title()

replace this

$mypost .= the_title();

with

$mypost .= the_title('','',false);

Method 2

I guessed it! Read the first paragraph of this. Try it. I’m sure it will solve your problem.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x