$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
- Output in XHTML or HTML 5 for plugins?
- How do I add a widget programmatically to a newly created site (WPMU) within a plugin?
- How can I save repeatable fields with one value inside an array?
- Rename existing old uploaded images containing accented French characters (not during upload)
- wp_verify_nonce() why return false?
- How to call bind function in wordpress actions or hooks
- How do I turn a custom post type into a plugin?
- Does WP identify plugin by plugin name or plugin_basename?
- Modifying Author Link to add Author Meta in URL
- How to create a custom post type that contains another custom post type?
- Add action to fire when a published post is updated
- How to make multiple admin pages for one plugin?
- Amazon.com intergration with WordPress?
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- I want to generate the pdf and save it in library?
- auto activate plugin when theme is active
- WordPress UPDATE queries on MySQL database stuck
- Where do the section input fields values are stored in database
- WordPress menu and plugin installation problem
- How to customize ‘recurrance’ of’ wp_schedule_event’?
- Call current post parameters inside a plugin
- Deprecated error notice
- Admin access to WordPress site with installing plugin