The main problem is how you’re specifying the custom table name (e.g., $wpdb->cf7dbplugin_submits
).
$wpdb
only knows about the “built-in” tables when accessing a table name via $wpdb->xxx
. To specify access a custom table name, use {$wpdb->prefix}custom_table_name
.
The other thing I notice is that, for security purposes, you should never use interpolated variables
in an SQL statement passed to any of the $wpdb
query methods. Instead, you should use $wpdb->prepare().
Putting these 2 things together results in:
$sql = $wpdb->prepare (
"SELECT min(TIMESTAMPDIFF($day,`fecha_inscripcion`, $now))
FROM {$wpdb->prefix}cf7dbplugin_submits
WHERE field_name=%s and field_value=%s",
$fieldname,
$fieldvalue
) ;
$post_count = $wpdb->get_var ($sql) ;
Related Posts:
- What argument does my function need to echo get_results() query results
- Pagination with custom SQL query
- How to make an activities stream mixing posts and comments?
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Select from wp_post and multiple meta_value from wp_postmeta
- How to correctly pass values to wpdb->prepare()?
- $wpdb select date range of posts
- How to delete taxonomy term when a wordpress user is removed?
- How to pass orderby params to $wpdb->prepare()?
- List of ways to access WordPress database?
- Passing a SQL query to the WP Query
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Include post_status check within $wpdb query
- wpdb LIKE request shows all database data
- Convert a WP Query into a simpler SQL query to fetch only COUNT of posts
- How to query custom post types with mixed AND & OR statements for custom fields
- Is there a WP function to get taxonomy name from taxonomy_term_id?
- wordpress ajax relationship query
- Query most popular terms by taxonomy over 2 week period
- Which is faster wpdb & get_row or wp_query & ge_post_meta?
- how to access query string in wordpress?
- Custom query: Get all posts that are from a certain category?
- How to access custom WordPress database tables
- Ajax future single post query doesn’t work when NOT logged in
- Conditional sorting with variable using WP Query
- Is it safe to access the underlying mysqli object from \wpdb for custom queries?
- Merge two search functions for custom post type
- Debugging wp_query orderby for taxonomy
- Is it possible to query from external database? [duplicate]
- Include post content of linked posts in search
- Getting additional columns from sql
- WordPress query posts with multiple post_meta data
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- Error with function in functions.php?
- Specify strict ‘order by’ in WordPress query
- Getting rid of unwanted nonSQL syntax characters when debugging a query
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Does WordPress have something like Drupal’s DB API?
- get_post() is not returning correct value
- Exclude authors IDs from WP_Query
- Query where ANDing slug values not working
- Loading two different AJAX requests on two different pages
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- How to load a script code only in posts?
- Slow Query On Search
- Multiple meta_key ordering with pre_get_posts
- WP_Query: apply an SQL function to meta fileld value
- How do I fit WP_Query arguments into a function?
- Create a notification for post field
- Add URL Rewrite Rule To WordPress
- Trying to get property of non-object in: $wp_query
- WordPress dynamic AJAX query
- relation OR instead of AND – Filtered term ID’s in loop
- How to avoid filling up an array each time I run a WP_query?
- How to SQL query posts IDs by categories AND authors?
- Randomly select one of last 3 posts
- WordPress SQL JOIN query
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- get_var is neither a string, integer, or array …?
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- how to translate countries output from wp database?
- What’s wrong with this wpdb query?
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- SQL query injection with fifu image
- duplicated posts when using pagination
- WP_Query() not working as expected
- Save queried result into database
- WP Query – grouping posts by same meta key, adding together values from another key
- Pagination repeating posts on search results
- sort title descending with title with number
- Delete oldest wordpress post (SQL query)
- How to check if logged in user have pending custom post?
- Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value
- What is the equivalent WP_Query of a SQL Query?
- Custom WordPress post query for displaying time-released content on website
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- How to get user avatar via WPDB
- Custom query for custom post type not getting correct post ID
- Translating WP query into to SQL query
- Modify post image in full size
- Finding post ID dynamically on click
- how to move a page from one drop down menu to another drop down menu
- How to upload 3 attachments to current post?
- Filtering posts for unique titles, only the most recent
- Global page ID variable empty error
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- How to search CPTs in draft using get_page_by_title()
- In which file to use $wpdb and its functions for database operations and queries in wordpress?
- WP_Query & shortcode : Return 3 articles from a category WordPress
- Calculating efficiently on large amount of data generated by wp_query
- Get post Number with local loop and template
- Save query in function for custom gallery
- Seach and categories not working when ignoring sticky posts in main loop
- Problem with custom WP_Query and underlying pagination/posts_per_page
- Calling a function with WP_Query only ever brings the first result
- complex query question
- Select Unique Posts for a List of Tags
- Fetching $_POST from Page Template into functions.php
- How To Use WP_Query To Get The Custom Post type Posts With Keywords
- wpdb get_results() returns only 2 rows