• Resolved macaela007

    (@macaela007)


    Hi have this function that is meant to return all the post of category news, the problem is that is only returning one post of that category I want to return all the post.

    <?php
    //function to display the third last news published
    function wptuts_third_last_news_shortcode($atts, $content=null) {
    query_posts( 'category_name=news' );   if (have_posts()) :
          while (have_posts()) : the_post();
    	 		 $blog_link = get_permalink(); // this si the link
             $return_string =  "<a href=" .$blog_link .">" . get_the_title() . "</a>" ;
          endwhile;
       endif;
       wp_reset_query();
       return $return_string;
    }
    add_shortcode( 'third_last_news', 'wptuts_third_last_news_shortcode');
    ?>

    can someone help me ouyt please thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • try to add the ‘posts_per_page’ parameter to the query:
    https://codex.www.ads-software.com/Class_Reference/WP_Query#Pagination_Parameters

    and concatenate the return string:

    $return_string .=  "<a href=" .$blog_link .">" . get_the_title() . "</a>" ;

    Thread Starter macaela007

    (@macaela007)

    Hi is working perfect thanks alot I’ll post the whole function here in case someone pump into in the future.
    once again thanks alot

    <?php
    //function to display the third last news published
    function wptuts_third_last_news_shortcode($atts, $content=null) {
    query_posts( 'category_name=news' );   if (have_posts()) :
          while (have_posts()) : the_post();
    	 		 $blog_link = get_permalink(); // this si the link
            $return_string .=  "<a href=" .$blog_link .">" . get_the_title() . "</a> <br />" ;
          endwhile;
       endif;
       wp_reset_query();
       return $return_string;
    }
    add_shortcode( 'third_last_news', 'wptuts_third_last_news_shortcode');
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Functions only returning one post when it should show all’ is closed to new replies.