$wpdb->prepare()
doesn’t actually fully support sprintf()
placeholders.
From the Codex:
The query parameter for prepare accepts sprintf()-like placeholders. The %s (string), %d (integer) and %f (float) formats are supported.
It’s not entirely obvious from that but the argument swapping formats (e.g. %1$d
) are not supported (in any case you have the incorrect syntax: it should be %2$s
instead of %2s
)
global $wpdb;
$wpdb->prepare(
"SELECT * FROM location
WHERE name LIKE %s OR name LIKE %s",
'%'.$wpdb->esc_like('on'),
'%'.$wpdb->esc_like('on').'%'
), ARRAY_A);
I’m assuming ‘on’ might be replaced by a unknown value – otherwise $wpdb->prepare()
isn’t necessary. On an unrelated note, the second condition in your SQL makes the first obsolete.
Related Posts:
- Redirect to another page using contact form 7? [closed]
- Delete data from custom table when deleting a post
- WP Forms not displaying,becomming an fatal error
- How can I make it so the Add New Post page has Visibility set to Private by default?
- Creating two database tables via plugin
- Query Posts by Custom Field ‘Price’
- Add section (add_settings_section) to a custom page (add_submenu_page)
- Show Similar Post Titles ( Similar to Stack Exchange )
- How to add option box in “Edit Post” plugin API?
- How do I unlock a post programmatically?
- How to call “page specific menu items” in template [closed]
- How To Ignore a Filter On Applying Filter the Content In a Function
- How to get posts by content?
- Publish Post After Click On A Link
- How to extract images of post and pages excluding header and logo image in wordpress?
- Action on post publish
- Accessing GET variable named ‘error’
- Adding Attachment Display Settings in custom media frame
- WP_Query ordering numbers as letters
- Execute a plugin only on post pages
- How can i list random post from multiple category?
- How to make a customize role and view a specific plugins base on that role?
- Accessing post’s meta data based on user’s click of a post
- How do I “get the next 10 posts after post_id == x”?
- switched from query_posts to WP_query, not working now?
- AJAX search posts and pages
- finding whether request is for post, and post id
- Display post lists in 2nd paragraph
- how to use in custom single.php template using php?
- How to create a custom shortcode based on the layout?
- How to get all posts belongs to a user between a certain date
- Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
- Post status doesn’t update to ‘future’ every time?
- Plugin is creating posts twice
- How do i specify a url to which to redirect the user after he logs out from facebook?
- I cannot include a file in my plugin settings page
- How to get Recent Post From Each Category with Thumbnail?
- help intercepting save_post through plugin
- Is it possible to pin a post in second position from top
- Help to Create a Simple Plugin to make a post
- How to Join wp_posts & wp_postmeta table using custom query
- How to display the custom post related blog by category?
- adding dynamic/multiple slug values in ‘option_none_value’
- How can I see $post object in frontend from functions.php?
- Allow members to create groups on my site
- add tags to wordpress post using REST API
- Performance considerations – postmeta table versus new table for custom posts with foreign keys?
- Prefix WordPress Taxonomy Tags With Hashtag Symbol Like Twitter
- Create survey that redirects to sidebar menu customized to answers
- Checkbox field that add a subscription product and change prices of other products in checkout and cart page
- WordPress Product Detail and catalog
- Is it possible to create duplicate post on other site (either push, on publish, or pull, periodically)?
- How to use information from the database in the front-end?
- How can I get the Post ID and Post Type within a Must Use Plugin?
- Get content and send to 3rd party
- How to insert variable which contain array value in wp_options table?
- Displaying friend’s posts only
- Trending Tags based on post views
- Shortcode in a blog post, footer and related products stop working
- How can I pass value to function in add_menu_page?
- Ger posts from similar tags and categories
- WP-Snap too slow (caused by WP_Query?)
- WordPress Meta Query: Relation is not working correctly
- WordPress ultra slow if I click on posts?
- Redirect url in plugin to somewhere else?
- Get page type to display content
- Insert data in custom table during new post creation
- Capturing POST data
- Making a Custom Post Type Publish Loop
- Checking url from plugin [duplicate]
- Custom feed parameters / Template overriding
- How can I create a navigation menu in the sidebar that can also act like a slider?
- Plugin to display text before a post
- Automatically put a menu on every post
- Plugin: Custom menu item problem
- warning wp session
- Accessing Correct Database to Create REST API Endpoint
- What is the easiest way to create a custom field archive?
- WP_Query does not return the result even if the data is present in the database
- Show the author only own types of publications. (JetEngine, Elementor)
- How can I keep a WordPress dropdown menu open when navigating to a child page?
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- How Can A Plugin Hook Itself To the End of Every Excerpt?
- Allow Facebook to preview posts before published
- How do I create an archive page for standard posts?
- Can I run multiple queries with $wpdb->prepare?
- Creating a menu page in a Object Oriented developed plugin
- Way to hook into a sidebar call to replace it with a custom sidebar
- How to submit documentation with plugin
- Is this plugin being loaded before file.php, subsequently not allowing me to use certain functions?
- Set attached to state
- I would like to use create a function in my custom plugin to tell WP to use a different header
- Use plugin or custom post type for game score functionality
- template_redirect not being called when using ajax
- How to get the permalink of a page when loading my plugin
- Has anyone used require.js for handling plugin scripts?
- WordPress plugin for mail subscriptions [closed]
- Having separate plugins and themes folder for multi-site setup
- Can WordPress plugins “Talk to each other”?
- How could I execute my plugin just in frontend (not in backend)