Yes, I think your quotes after the WHERE are backwards. Try it like this:
...$fields.' WHERE wp_users.ID='.$current_user->ID );
The “WHERE wp_users.ID=” part is plain text that is intended to be part of the query, so it needs to be in quotes. The $current_user->ID is a variable that should live outside the quotes.
If that doesn’t work, I would suggest using a variable to store the SQL query and then output it as debugging. That way you can see what is being formed and see if it is what you expect.
This is how I do it:
$sql = db->prepare( "SELECT * FROM $table WHERE user=%s", $current_user->ID );
Hope this helps!
BTW, it took me awhile to get used to using a period as a concatenation operator.
Related Posts:
- How to make WordPress plugin check for database changes and then do something?
- Database “Migration” for Plugins?
- See output of a sql query while plugin installation in wordpress
- How to properly prepare a column name if passed to a stored procedure?
- Should I use spl_autoload_register() in my plugin?
- How can I save a multiple select array with the settings API for a plug-in options page?
- error_log() output for print_r() appearing on page
- Include WP_Query in my own PHP file?
- When to use Exceptions vs Error Objects vs just plain false/null
- Using register_activation_hook in classes
- Transaction when using WP functions rather than vanilla SQL?
- $wpdb->get_results(…) returns empty array despite correct query
- Allow only 1 taxonomy per custom post type [duplicate]
- Custom plugin: Trying to show saved data on frontend
- Uninstalling a plugin: delete all options with specific prefix
- Is there a way for a plugin to add an attribute to the tag of a theme?
- WordPress URL Rewrite not working
- Do I require the use of nonce?
- How to get the list of WooCommerce product image of a certain category from database?
- Fatal error: Call to undefined function plugin_dir_path()
- How to use update and delete query in wordpress
- Detect a focus on wp_editor
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- I can’t fetch query parameters ($_GET parameters) with get_query_var
- Retrieve multiple values passed to a single attribute in a shortcode
- Alter query on edit.php
- Change Password Hint
- Dynamic URL to reference custom PHP files
- How to auto login user again after change user_login
- How to display multiple Post meta_key/meta_values by SQL query
- Display a text message if the shortcode is not found?
- add_meta_boxes action with refresh on save
- How to change date language without changing the entire site language?
- How to Join two tables from separate databases within WordPress
- count number of user comments with a specific comment meta value
- Save selected item from dropdown menu in a meta box as a metadata value for a custom post type
- Prevent multiple counts by same user – WP PostViews plugin
- simple wordpress ajax plugin not working when not logged in
- How to use copy() function and paste file in /wp-content/themes directory
- Second select list values are not saved after clicking update
- Use wc_enqueue_js only on specific pages – nested add_action
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- How to use a frontend URL with a Plugin
- Utilize WP-CLI from inside WordPress, not SSH
- Saving metabox repeatable fields
- OOP Plugin Development. Including external object
- Authenticating to WordPress, using my own authentication two-factor system
- Use composer to load custom classes [closed]
- Resize Image without cropping
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- how to create and show sessions in word press?
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- wordpress custom endpoint multiple params
- Loading page template into shortcode
- WPDB: how to get the value of a field in a custom database table
- Why when I instantiate wp_error in a validation method my user registration method stops working?
- My shortcode is showing up twice
- WordPress template_include filter not working properly
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- When is is_admin() available?
- Create table in database when activating plugin
- do not show web page section when using advanced custom fields pro
- How to get all existing post types
- my function doesn’t return my post from today
- Using wp_get_image_editor in a standalone script
- New Plugin Review
- Problem with WordPress Ajax form
- Create custom blocks for bootstrap
- Theme url in all plugin pages
- Enhanced WordPress Search
- allow user to select pages from dropdown in my plugin
- Am I not understanding plugins?
- Continue execution after WP REST API response
- WordPress Ajax Custom Query – High CPU LOAD
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- Using Font Awesome as post thumbnail
- How to display a value from a radio button in the options menu in wordpress
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- allow users to publish without admin approval
- Automatically generate Post/Page from searched Database item?
- List of posts by day of the week
- How to set a custom path, for ajax image upload folder in admin?
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- register_activation_hook isn’t adding table to DB
- How to display posts of specific category using a custom Query in WordPress?
- admin-ajax.php responding with 0
- What SQL / WordPress queries would need a nonce?
- Making Quote Plugin more efficient
- How to access function from outside of a class within this class in WP plugin?
- Hiding WordPress Plugin Source Code
- Renaming post IDs – Okay to do?
- How can i display post loop in table format?
- How to generate page content from database the right way?
- Page Reloads Before AJAX Request Finishes
- action hook wp_head higher priority as all other plugins/hooks
- How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- PHP can I add line numbers to file_get_contents()
- Add htaccess rules with insert_with_markers at beginning of htaccess
- custom shortcode will not display the wrapped content