Home › Forums › ACF PRO › Repeater Fields and pre_get_posts › Reply To: Repeater Fields and pre_get_posts
To be honest, I don’t know exactly how to correct the problem your having. Usually, when I’m dealing with pre_get_posts problems I do something like this.
add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts($query) {
print_r($query);
}
This makes a mess of the site, but then I look at the source so I can see what’s being queried and figure out how to eliminate the ones I don’t want to change or target the one I do.
As far as the if statements, some of them can just be stacked at the beginning of the function, for example, if you never want to modify a query in the admin you can either do this
add_action('pre_get_posts', 'myprefix_query_offset', 1 );
function myprefix_query_offset(&$query) {
if (is_admin()) {
return;
}
if ($query->is_home()) {
return;
}
}
or this
add_action('pre_get_posts', 'myprefix_query_offset', 1 );
function myprefix_query_offset(&$query) {
if ($query->is_home() || is_admin()) {
return;
}
}
I would look for a way to white list the query you want to change, for example
if (!is_admin() &&
$query->is_main_query() &&
!empty($query->query_vars['post_type']) &&
$query->query_vars['post_type'] == 'post') {
// only on the main query
// make changes to the query here
}
That would narrow it down to posts and the main query, which I think is the query you are looking to change. checking for the main query should eliminate problems with any other query on the site…… which I should have thought of several sentences ago or maybe even when I was making my original comment.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.