Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default @posts to main query and accept query arg #1

Closed
wants to merge 1 commit into from
Closed

Default @posts to main query and accept query arg #1

wants to merge 1 commit into from

Conversation

mmirus
Copy link

@mmirus mmirus commented Dec 6, 2018

Thanks for this set of directives, @Log1x!

For your consideration...

This PR changes @posts to provide greater flexibility:

  1. Now defaults to the main query instead of $query
  2. Now can accept an optional argument so that you can pass a query to be used in

This would break backwards compatibility with previous @posts usage that defaulted to using $query.

Options for moving forward:

  1. Accept breaking change and use semver / docs to communicate it appropriately and help users know what they need to update (@posts -> @posts($query))
  2. Modify this PR so that if no query is passed to the directive and $query exists it defaults to that instead of to the main query

Updated docs:

@posts

@posts begins the post loop. It is wrapped in a have_posts() conditional and thus will return null if no posts are found.

@endposts is available to end your loop and have_posts() conditional as well as resetting your loop with wp_reset_postdata().

@posts defaults to the main query, but it accepts a WP_Query instance as an optional argument. If the argument is provided, @posts will use that query instead.

@posts
  <h2 class="entry-title">{!! get_the_title() !!}</h2>
  <div class="entry-content">
    @php the_content() @endphp
  </div>
@endposts

@posts($other_query)
  <h2 class="entry-title">{!! get_the_title() !!}</h2>
  <div class="entry-content">
    @php the_content() @endphp
  </div>
@endposts

Log1x added a commit that referenced this pull request Dec 7, 2018
Add missing @isoption directive
Allow @option to accept a second parameter to return a value in an array
Fix @options param typo
Clean up @sub, @hassub, and @issub
Clean up @condition syntax
Allow @posts to accept a custom WP_Query instance as a variable as well as return the main loop if $query is undefined and no variable is passed. (Thanks to @mmirus on #1)
Add @title, @content, and @ExceRPT WordPress directives
@Log1x Log1x closed this Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants