• Hi al,,

    I’ve a question regarding implementing the following functionality. If a specific page is requested, i want to switch the content based on some option set in the admin screen.

    My main idea was to use pre_get_posts to change this behaviour. However,the documentatation explicitly lists: ‘pre_get_posts should not be used to alter the query for single Page requests’. Now, my main question is: which hook should I use to override the WP_Query object pointing to the new page?

Viewing 1 replies (of 1 total)
  • If I’m understanding you correctly, you’re looking to just show a specific set of posts on a page? Usually you’d create a custom template with your custom query on it instead of using a default template in WP.

    As far as switching something based on something used in the admin screen, I’ve used Advanced Custom Fields plugin for adding an option to a post screen, then filtering my WP query (in my custom template) based on that option at the time the page is rendered.

Viewing 1 replies (of 1 total)
  • The topic ‘Modifying Main Query Single Page Request’ is closed to new replies.