I have read Using pre_get_posts with WP_Query and I'm not sure where to go with it.

I have a recent posts plugin which adds variables to WP_Query - one of which can be 'offset' posts. The problem is I have multiple instances of recent posts according to category and if I want an offset of 4 it offsets posts in the category rather than simply the latest 4 posts irrespective of category (I guess as part of $args see code).

It feels like I need to filter the latest 4 posts from WP_Query before it is passed to recent posts but I'm not sure this is possible?

I've played with various snippets but haven't got anywhere. So far I am left with...

add_action('pre_get_posts', 'skips_front_page_filter');
$flexible_posts = new WP_Query( $args );
remove_action('pre_get_posts', 'skips_front_page_filter');

All I've done is surround $flexible_posts = new WP_Query( $args ); with an action. Am I going about this the right way and can anyone assist me to strip the first 4 posts irrespective of category before it hits $flexible_posts?

There is a second part to this. I only want this filter to apply when my static front page is visible. I tried if( is_front_page() ) but that hasn't helped although until I can get the filter working that's a secondary issue to worry about.

Would appreciate any help.

| improve this question | | | | |
  • Please show your complete code. Without seeing that function and to see your wrapper (and where it's attached), it's impossible to know. – kaiser Aug 17 '14 at 18:23
  • @kaiser thank you for responding. It is a free plugin - flexible posts widget. Is it acceptable to paste the full PHP code here? It is quite lengthy. – Paul Brown Aug 17 '14 at 20:28
  • Just paste the needed bits to understand what you are trying to do. – kaiser Aug 17 '14 at 22:34
  • Thank you @kaiser actually, I think I'm trying to force something that the existing code isn't structured for. I'm going to bin the idea but I appreciate your help. Sorry to waste your time. – Paul Brown Aug 17 '14 at 22:39
  • Paul, that really isn't descriptive. If you are trying to work around what the plugin provides, then please put what the plugin does in here. But just the bits that are needed to understand what the problem you are trying to solve is. – kaiser Aug 17 '14 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.