• hemasusi

    (@hemasusi)


    Hi,
    We have posts to show in the news page under categories..
    We created a page “News & events” in “News category 1” & created many posts in “News category 1″ as well..
    Now the coding of the news template is below:

    https://prnt.sc/1x2mpgd

    This displaying only 15 posts out of 20..
    In Admin Settings> Reading > Blog pages show at most – set as 16
    It is showing only 15… My Question is two.

    1. My News and Events page id is 812… My one of the post id among 20 posts is 812. So when i write the query as get_posts with post_type => ‘post’ , it gets the page also.. So the page name & created date also displaying as one of the post in the news page. So total 15 posts(out of 20) are showing & 1 is page name showing..

    For this reason only we wrote the if coding as => if($page_id != $post_id):

    We need to get posts only (except page). what to do?

    2. Second question is I have mentioned the ‘numberposts’ => -1” in the query.. But it is getting the posts which was set the count in Admin Settings> Reading > Blog pages show at most – 16. So it takes the settings count only.

    I need to show the all posts in my page. so what to do for this also?

    Kindly answer for these two queries.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    There is no 'numberposts' => -1 arg in your query, hence if falls back to the posts per page setting. Also, AFAIK there is no valid “numberposts” arg. There is “showposts”, but it’s deprecated. You should be using “posts_per_page”.

    If you’re getting pages when you supply `’post_type’=>’post’, there is probably other code somewhere altering queries, usually through “pre_get_posts” action. You can use the “Query Monitor” plugin to examine the actual SQL used for any query.

    If nothing else, you can exclude a specific post or page (like the current page) from query results by using the “post__not_in” arg.

    I recommend avoiding the use of the @ (suppress errors) PHP modifier. If your code is erroring out, you should want to know about it. Reserve @ usage for calls that depend on external resources you have no control over. Even then, ideally you’d install a proper error handler or try/catch structure.

    When you post code, it’s better to post actual text so others can further test your code if necessary. Please avoid posting code screen grabs. You can use pastebin.com to share code snippets as text.

    Thread Starter hemasusi

    (@hemasusi)

    Thanks.. I have tried ‘posts_per_page’ => -1.. It is working.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Blog List – Limit’ is closed to new replies.