When working with database in WordPress you should never use the low lever mysql_*
or mysqli_*
functions.
Always use $wpdb
methods, in your case you should use prepare()
:
$query = $wpdb->prepare(
"SELECT post_title from $wpdb->posts
WHERE post_title LIKE %s",
"%" . $myTitle . "%"
);
Moreover, once you are getting a single column, you have easier life using get_col
instead of get_results
:
$myposttitle = get_col( $query );
Related Posts:
- How do you properly prepare a %LIKE% SQL statement?
- $wpdb and MySQL Create Trigger
- wpdb->prepare function remove single quote for %s in SQL statment
- Increment value (value = value+1) of $wpdb->update
- wpdb Custom Meta Data with 2 conditions
- wpdb prepare syntax
- SQL query not working in alphabetical post title/content search
- MySQL LIKE not working
- Proper way to work with wpdb to get user’s firstname
- How to check for empty and not a failure
- Database: Custom table: sprintf value for DateTime column
- Converting mysql to $wpdb
- WP_USE_EXT_MYSQL
- wpdb insert and boolean fields
- Join new table with SQL query
- writing inner join in wpdb
- How to split the a table in database?
- MySQL Rank & $wpdb
- When WordPress Default table, Echo Success. When Plugin Table, Echo Blank
- How do I join a $wpdb query with user meta using default value if not exist?
- How to translate this mySQL query to $wpdb query
- $wpdb select all meta for each post
- $wpdb to insert html form information
- Proper usage of $wpdb->update()?
- WordPress(wpdb class) and mysql stored procedures
- Can’t run database query
- Using WPDB->Insert()
- Active DB queries in WordPress?
- How to stop $wpdb from prepending database name
- WordPress $wpdb get posts from category and sort by custom meta
- How to get INSERT errors from $wpdb?
- Getting Error Trying to Create Table
- How to set MYSQLI_OPT_INT_AND_FLOAT_NATIVE option
- Understanding custom php that reads from WP MYSQL
- How to insert dash (-) into database using wpdb and new_to_publish hook?
- $wpdb->get_var multiple queries in one database check
- List users with the most posts in the last 30 days
- Insert two row in wordpress database
- WordPress $wpdb no result
- PHP variables in mysql query
- MySQL ‘duplicate entry’ error
- User set date and time from frontend doesn’t get stored into database
- Wpdb query with dynamic table name
- get posts whether meta_key exists or not
- when using $wpdb sudden connection rejection without changing anything. Access denied, with errors from repair tool
- How to search usermeta table
- How to add virtual column in wpdb get_result statement
- wpdb insert into point column in db
- WPDB delivers wrong results from complex queries
- $wpdb post type and term query only works when there are no dashes or spaces in the term slug and title
- CONCAT_WS in custom sql query
- Geographical proximity query using post_meta
- MySQL Select within WP Page template
- Saving custom term value to the database in new table
- why is $wpdb->update() causing a DB error from within wp_set_password()
- $wpdb->get_var returns 0
- Initialization of table in database using ‘CREATE … IF NOT EXISTS’
- Not unique table/alias
- Install mysql-python (Windows)
- MySQL WHERE IN ()
- How can I prevent SQL injection in PHP?
- Best way to store an array in MySQL database?
- How to grant remote access permissions to mysql server for user?
- #1062 – Duplicate entry for key ‘PRIMARY’
- How can I convert a string to a float in mysql?
- Is there a Profiler equivalent for MySql?
- How to use greater than operator with date?
- How to return number of found rows from SELECT query
- How to replace the domain name in a WordPress database?
- What causes the “max_user_connections” warning on WordPress frontend?
- WordPress Deadlock Error
- How to do a MySQL dump from production site without using a search and replace script for local development?
- Concurrent / simultaneous MySQL connections
- How many ‘wp_insert_post’ calls can be performed in one shot, in a very long ‘for’ loop?
- Advanced SELECT query with condtional statements
- Replacing link URL ending strings via MySQL
- Problem with admin login after deployment
- Find out how many times the user has logged in
- Placing a widget with $wpdb query
- How can I add a new row in a separate database when someone registers via WordPress?
- Get posts from category with custom query
- How to use mysql LIKE with wpdb?
- Best approach for a custom database filling in WP custom post types
- How to use AJAX in WordPress in MYSQL query?
- WordPress Insert not working with ajax
- Passing in MySQL prepare statement parameter separately throwing error
- Database SQL query error
- How to Bulk find and replace MySQL for post image url
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- update multiple rows in mysqli table base on two values
- Not getting ajax success response on insert/update row to database
- How can I verify WordPress nonce from the following code?
- What is the cron doing?
- Apache Redirect based on WordPress permissions
- SQL error on restoring database
- MySQL database gives blank page (white screen of death)
- Datatabase error: Commands out of sync
- Global MySQL replacing of text patterns/matches
- Why does the MySQL command line tool ignore the –port parameter?
- Postgres equivalent to MySQL’s \G?