Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Login Api with Meta_key and Meta_value

To log a user in you really only need the user’s ID. Based on your info you should be able to obtain it from the username field.

// Get User object
$user = get_user_by( 'login', $username );

// Clear any auth cookies
wp_clear_auth_cookie();

// Log the user in
wp_set_current_user( $user->ID );
wp_set_auth_cookie( $user->ID );

On a non-login page you could probably refresh right after;

header("Refresh:0");
exit();

Now that the hard part is out of the way, it comes down to where you’re getting your username from.

Most people don’t store username/password in plaintext on post_metadata. But even then, and you’re making a whole loop query for login data, you’re still going to have to settle on logging in a single user. So the whole $data['result'][]= doesn’t make a lot of sense.

Related Posts:

  1. Login & Register & Custom details WITHOUT plugin
  2. Login WP – Connect single field to an external api
  3. help for user login
  4. Login_form add to top of form rather then bottom
  5. Create custom fields/meta data gender+country – radiobuttons and dropdown on register screen for these fields
  6. Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
  7. WP_Query – Order results by meta value
  8. Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
  9. getting all values for a custom field key (cross-post)
  10. How to add a custom field in the advanced menu properties?
  11. Custom query with orderby meta_value of custom field
  12. How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
  13. Using meta query (‘meta_query’) with a search query (‘s’)
  14. Can I exclude a post by meta key using pre_get_posts function?
  15. Add validation and error handling when saving custom fields?
  16. Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
  17. Show Custom Fields in Quick Edit
  18. Where are custom field values stored in the database
  19. Validating Custom Meta Box Values & Required Fields
  20. Max length of meta_value
  21. Add custom fields to wp native gallery settings
  22. How to fix missing custom fields after upgrading to WordPress 4.8.1?
  23. How to enable custom fields for pages (if not a bad practice)?
  24. How can I add extra attribute in the ‘Page Attribute’ section in wp-admin for pages?
  25. Is there a way to set default custom fields when creating a post?
  26. Custom post meta field effect on the performance on the post
  27. How to get custom post meta using REST API
  28. Custom field/meta populated by dropdown of existing posts?
  29. Difference between meta keys with _ and without _ [duplicate]
  30. Is there any action filter/hook for validating a custom field before publishing the post?
  31. Remove Dimension from wp_get_attachment_image
  32. Orderby meta_value only returns posts that have existing meta_key
  33. Underscores in custom fields
  34. What is the index [0] for on post meta fields?
  35. What is “meta_input” parameter in wp_insert_post() used for?
  36. Query Posts or Get Posts by custom fields, possible?
  37. How to enable revisions for post meta data?
  38. Sortable Custom Columns in User Panel (users.php)?
  39. Any way to add custom options to Gallery Settings?
  40. The “_encloseme” Meta-Key Conundrum
  41. ORDER BY custom field value
  42. Individual Widgets per Page
  43. Add subtitle to Woocommerce product title
  44. How to protect pages with double authentication: password + email (in custom field)
  45. Best way to programmatically remove a category/term from a post
  46. Importing data for advanced custom fields plugin?
  47. Gutenberg add a custom metabox to default blocks
  48. SQL Query to copy value of a meta_key into another meta_key
  49. ‘Preview Changes’ for custom meta boxes?
  50. Adding a custom field to the site identity menu
  51. Using TinyMce with textareas in meta boxes on custom post types
  52. Filter WP_Query for posts having a certain meta-value
  53. How to correctly call custom field dates into a posts_where filter using SQL statements
  54. Using get_post_meta with new_to_publish
  55. Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
  56. Add a Jquery Datepicker to custom field in post edit
  57. add meta box – custom field : which to choose?
  58. Preserving line breaks when saving and displaying custom fields data
  59. How to return Meta data from the REST API?
  60. Advanced Custom Fields – Get custom fields from parent page
  61. Can I query custom meta data through WP_Query
  62. Add custom field to the archive page?
  63. Saving custom data for each user
  64. Is it safe to store a user setting you don’t want the user to ever modify as a user option?
  65. Tabindex on text input immediately after WordPress title input
  66. Including custom fields in search?
  67. Add custom fields to search
  68. SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
  69. Attaching Metadata to a Taxonomy Item
  70. Add metabox to document tab in gutenberg
  71. How to display all custom fields associated with a post?
  72. How to add add_meta_box to specific Page Template?
  73. How to rename a custom field?
  74. Apply the_content filter to a custom field with multiple values
  75. Filter post listing by meta value which is a date
  76. Extra profile field as select box?
  77. Matching Serialized Arrays with meta_query
  78. How can I make wp-pagenavi work on a custom query built upon a form submission? [closed]
  79. Custom field metabox not showing in back-end
  80. Meta Query with AND & OR?
  81. Pre-filling custom fields on New Post
  82. Having different sidebar content for MANY pages?
  83. So much data in postmeta
  84. Custom search: by post data and post metadata?
  85. How to access custom order item meta data from a meta key in WooCommerce?
  86. Problem with serialized arrays in custom meta
  87. Show only posts which can be commented OR have custom meta field
  88. Add custom objects/entities to WordPress
  89. explode array within shortcode
  90. Can I count the number of users matching a value in a multiple value key?
  91. Pass all custom fields through the same filter on post load?
  92. Need small coding with Custom Fields Search
  93. Change behavior of “Insert into Post” based on attachment metadata
  94. How can I append custom data to images in the editor?
  95. Using get_posts with arguments found in meta keys
  96. Add custom fields when specific templates are selected
  97. Sort posts by custom field numeric value using dropdown
  98. Adding Custom Field to Taxonomy Input :Panel
  99. How to position a custom field before the editor
  100. Display custom field value on woocommerce product page
Categories custom-field Tags custom-field, login
Calling a function with WP_Query only ever brings the first result
current_time(‘timestamp’) is wrong

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress