• I would like to completely eliminate the loop via plugin. My thought is to set has_posts() = false but it does not seem to work.

    Alternatively, I guess I could stop the query entirely.

    ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • What do you mean by “completely eliminate the loop”?

    can you describe what you want a bit more?

    Moderator bcworkz

    (@bcworkz)

    You can set a query var in the ‘pre_get_posts‘ action to some impossible value so the query always fails to return something. You must do so within a conditional, or else you would cause ALL queries to fail, such as queries for the nav menu, etc. Alternately, only add the hook when conditions are correct.

    This would typically cause a ‘no posts found’ section of the template to execute. So you probably need to override the default template loaded anyway. If you do that, just use a template that doesn’t have a loop in it and forget playing with ‘pre_get_posts’.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Eliminate the loop with plugin / force have_posts = false’ is closed to new replies.