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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for non empty search arg #391

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Alexays
Copy link

@Alexays Alexays commented Sep 29, 2020

Hi, @elliotcondon

In case we're using acf/fields/post_object/query and unsetted the s arg in order to use something like post__in this cause a warning.
Here's the fix 馃槂

@elliotcondon
Copy link
Contributor

Hi @Alexays

Thanks for the PR and fix. I'm always interested in avoiding PHP errors, but would like to better understand the context when you are unsetting the search parameter. Are you performing some kind of custom search? Or are you preventing search completely?

@Alexays
Copy link
Author

Alexays commented Sep 30, 2020

Hi @Alexays

Thanks for the PR and fix. I'm always interested in avoiding PHP errors, but would like to better understand the context when you are unsetting the search parameter. Are you performing some kind of custom search? Or are you preventing search completely?

We're unsetting the search parameter and set the post__in param in order to search by post ID/post URL directly.

Here's an example:

add_filter('acf/fields/post_object/query', array($this, 'alterQuery'), 10, 3);

public function alterQuery($args, $field, $post_id) {
        // Get search query
        $search = $args['s'];

        // If post id, return post asked
        if (is_numeric($search)) {
            $args['post__in'] = array((int) $search);
            unset($args['s']);
            return $args;
        }
       return $args
}

@elliotcondon
Copy link
Contributor

Well that's a pretty good explanation! Thanks mate. Leave this with me, and I'll do my best to incorporate it into the next release.

With my dev workflow, I work on the PRO version, and then sync those changes down into the free one (not the other way around), so I technically won't merge in this PR.

Thanks again for raising the issue. I should have this fixed in 5.9.2

@elliotcondon
Copy link
Contributor

Hi @Alexays. Quick update on this issue. I've manually implemented this in the PRO repository and will include this in the next release (5.9.2). Thanks again for your help. I'm looking forward to overhauling these AJAX queries in the near future!

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.

None yet

2 participants