Home › Forums › Backend Issues (wp-admin) › Post Object search by ID or SKU › Reply To: Post Object search by ID or SKU
Going to be honest, I don’t generally do things like this, all I can do it repeat the examples.
Basically you add an acf filter for your field
add_filter('acf/fields/post_oject/query/name=YOUR-FIELD_NAME', 'YOUR_FUNCTION_NAME', 10, 3);
function YOUR_FUNCTION_NAME($args, $field, $post_id) {
// inside of this filter you add the filters described
// for searching post meta
// as described here and in other places
// https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/
// this is done so that the filters will only be added for
// this particular field in the admin
add_filter('posts_join', 'cf_search_join');
add_filter('posts_where', 'cf_search_where');
add_filter('posts_distinct', 'cf_search_distinct');
}
Then you add the other function to search by what you want to search by. You will need to refer to the WC documentation for what field to look at for sku.
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.