Exactly right about resetting it! You should use wp_reset_query()
. Try this:
$num_res = $wp_query->post_count;
$get_search_term = get_search_query();
// No more work required for the query, so...
wp_reset_query();
if($num_res == 0)
{
$args = array(
'post_type' => 'resources',
'meta_key' => 'resource_txt',
'meta_value' => $get_search_term,
'meta_compare' => 'LIKE' );
$custom_query = new WP_Query( $args );
// Do stuff here.
wp_reset_query();
}
It is a good habit to reset the query once you’ve retrieved what you need from it.
Related Posts:
- Cannot add or update a child row: a foreign key constraint fails
- Cannot add or update a child row: a foreign key constraint fails
- Cannot delete or update a parent row: a foreign key constraint fails
- ERROR 2003 (HY000): Can’t connect to MySQL server on localhost (10061)
- Rename a column in MySQL
- Not unique table/alias
- Install mysql-python (Windows)
- #1055 – Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this is incompatible with sql_mode=only_full_group_by
- Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
- Select from multiple tables without a join?
- SQL Query Where Field DOES NOT Contain $x
- Disable ONLY_FULL_GROUP_BY
- MySQL WHERE IN ()
- SELECT list is not in GROUP BY clause and contains nonaggregated column …. incompatible with sql_mode=only_full_group_by
- Host ‘xxx.xx.xxx.xxx’ is not allowed to connect to this MySQL server
- difference between primary key and unique key
- Mysql command not found in OS X 10.7
- How to export a mysql database using Command Prompt?
- MySQL AS keyword
- Should I use the datetime or timestamp data type in MySQL?
- Access denied; you need (at least one of) the SUPER privilege(s) for this operation
- MySQL Error #1133 – Can’t find any matching row in the user table
- How can I prevent SQL injection in PHP?
- Best way to store an array in MySQL database?
- MySQL date formats – difficulty Inserting a date
- Cannot connect to Database server (mysql workbench)
- How to grant remote access permissions to mysql server for user?
- How to check if mysql database exists
- #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?
- Data is not constantly loading from custom wordpress table
- How to replace the domain name in a WordPress database?
- Mysqldump add drop table?
- Optimize WordPress Query that take 5 seconds to execute
- MySQL Replication Latency Issues in wp-admin pages
- “#1067 – Invalid default value for ‘post_date'” when trying to reset AI after backup
- Increment value (value = value+1) of $wpdb->update
- #1115 – Unknown character set: ‘utf8mb4’
- How can I debug my database connection for unit testing?
- Extending the database
- SQL query not working in alphabetical post title/content search
- Universal problem: first request after ~25 second inactivity always slower (~1 second) than subsequent requests (~1/10sec)
- Importing MariaDB into Mysql in WordPress
- How to get a Google maps SQL->XML->map marker tutorial to work in WordPress
- Converting mysql to $wpdb
- Best settings for MySQL to speed up site? [closed]
- Update a WordPress post or page takes 60+ seconds
- add_post_meta does not respect the content
- Modify MySQL Query Based on Dropdown Menu
- Select multiple wp_postmeta keys with single select
- Can’t find my wordpress DB in phpmyadmin
- Deprecated: mysql_connect():
- Backing up and restoring multiple sites efficiently
- Alter wp_post table vs. post_meta performance/speed
- Calculate average crossing post categories
- SQL command to convert all tags in lowercase?
- Are these WordPress tables safe to add indexes to?
- Is it possible to create a WordPress table using array and loop?
- SQL syntax error when getting data for a url
- Import CSV to MySQL, with custom registration field information
- Locally restoring a ManageWP full site backup
- WordPress doesn’t save changes some times
- Match tag names with form titles
- Error missing MySQL extension
- Update Custom Post Type Taxonomies with SQL
- Getting Error Trying to Create Table
- Custom SELECT Query not returning the_title and the_permalink
- Will reducing mysql permissions hinder WP function? [duplicate]
- Php Mysql Terms
- Export SQL query based on custom field?
- SQL statement using placeholder is not returning results
- Lock wait timeout exceeded; try restarting transaction
- How to install WordPress from hosting service with mysql database from Compute Engine GCP?
- 504 Gateway Time-out after custom plugin inserts data into mysql database
- WordPress fails to install with “Can’t Select Database” Error (WAMPServer)
- What is this? MySQL array?
- Regular XML-RPC timeouts
- What is the MYSQL Query to bulk update the canonical URL of specific categories of posts in WordPress?
- Why should be SQL keywords, like CREATE TABLE and UPDATE, must be uppercase in WordPress?
- Add row to SQL array
- SELECT statement wrong?
- mysql query on wp_user and user_meta problem
- $wpdb post type and term query only works when there are no dashes or spaces in the term slug and title
- Custom user query – orderby meta_key (that may not exist)
- How to get Attachments(image) with specific width\height ratio
- 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
- optimise SQL wordpress call
- why is $wpdb->update() causing a DB error from within wp_set_password()
- Global MySQL replacing of text patterns/matches
- remove wordpress post links
- SQL get last entry of a specific gravity form
- mysqldump to a tar.gz
- How to check what port mysql is running on
- Where is my mysql log on OS X?