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
- 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?
- Include WP_Query in my own PHP file?
- Using register_activation_hook in classes
- Is there a way for a plugin to add an attribute to the tag of a theme?
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- Resize Image without cropping
- My shortcode is showing up twice
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- When is is_admin() available?
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- Automatically generate Post/Page from searched Database item?
- List of posts by day of the week
- What SQL / WordPress queries would need a nonce?
- Making Quote Plugin more efficient
- Hiding WordPress Plugin Source Code
- How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?
- Will simple function names in a class structure conflict with other plugins?
- Plugin Development sqlite or WordPress’ database
- Instantiate class to be available to all plugin functions
- How to test nonce with AJAX – Plugin development
- wp_loaded hook block script enquequing
- WP nonce invalid
- How can i upload images in an admin page?
- How to find error in my code when the error message is pointing to WP core file?
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Reprinting tags with all attributes
- developing a wordpress plugin, have a few PHP Woocommerce related coding questions
- Update results, Before deleting the related category [closed]
- Adding function to Genesis genesis_header [closed]
- $wpdb->insert() does not Insert record in a table
- how to update and display an option without reloading the page
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Plugin Generate Unexpected output during activation
- WordPress Environment: Dynamic Page using shortcode – how to change the page name for sharing
- Extend Woocommerce Widget Class – WC_Widget_Product_Categories
- Undefined method class::construct() when creating a plugin
- Hook called before text widget save
- zip unzip attachments in wordpress
- wpdb prepare insert table doesn’t work
- wordpress admin plugin menu custom css
- dynamic page using php from sql database
- How to Update post_modified of all wordpress post
- how to Update 15k products on plugin activation with meta_option
- Using admin-post.php for admin form but it directs me to admin-post.php white screen
- Filter results from a serialized string to use on statistics
- How can I display Custom Post type Custom Columns and its Content in a Dashboard Widget?
- Searching Posts Programmatically in a WordPress Plugin
- Adding Additional Variables on Menus Page
- Why my query does not run with prepare
- custom plugin with upload files does not work
- wpdb getting avatars and author url
- What is the difference between Null vs Empty (Zero Length) string?
- making php value numeric
- WordPress SQL JOIN query
- send popup after wp_redirect()
- no_rest_route error on custom routes
- How to correctly escape an echo
- Build A Custom SQL Query for WordPress Search
- How to run complex query using PHP
- Create ACF Checkbox to get all ACF Values from Parent Page
- Creating plugin with front-end pages
- Storing huge number of users in wordpress
- How to Send Pingbacks for all Posts in WordPress?
- Trying to create a shortcode to display categories with a specific product tag
- Creating multiple tables with Plugin
- File is executed twice if plugin is activating
- Custom User registration system
- product_type_options get saved value [closed]
- Display a custom name when the user has no name settle in his account
- Woocommerce – get daily sales meta
- get Woocommerce product format json for WP_Query
- Sum All the Post Meta of Published posts of Current Logged in user
- WordPress search query, how to modify the sql
- The plugin generated 225 characters of unexpected output during activation
- Autoloading Classes in Plugins
- Comparing Dates within plugin using PHP If statement
- Submit to itself don’t work
- WordPress / PhpStorm / XDebug and plugin_dir_path issues
- direct query to post_meta table
- What to create new post using wp_insert_post, but it repeat the post infinitely
- Send data from plugin to external database
- Why this plugin is not working?
- Permission error on plugin save
- Querying multiple meta_keys in WordPress SQL query
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- display php code in header using wp_head()
- base64_encode conflict with convert_smilies in wordpress
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Custom taxonomy with page post type – WordPress
- Query posts by custom taxonomy slug in WP REST API?
- oneOf JSON Schema validation not properly working for custom post meta value?
- Too few arguments at registering new templates in my plugin
- I want to lists posts in wordpress to nearest location entered by the user
- how to check elementor is widget is active or loaded