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

Is there a way to list tags order by post_meta field

$querystr = "
    SELECT DISTINCT
    -- post_meta.meta_value,
    key2.name as tag_name,key2.slug as tag_slug FROM $wpdb->posts key1
  LEFT JOIN $wpdb->term_relationships ON (key1.ID = $wpdb->term_relationships.object_id)
  LEFT JOIN $wpdb->postmeta post_meta ON (key1.ID = post_meta.post_id)
LEFT JOIN $wpdb->terms key2 ON ($wpdb->term_relationships.term_taxonomy_id = key2.term_id)
LEFT JOIN $wpdb->term_taxonomy key3 ON ($wpdb->term_relationships.term_taxonomy_id = key3.term_id)
  WHERE 1=1
  AND post_meta.meta_key = 'likes_count'
  AND post_meta.meta_value > 0
  AND (key1.post_status="publish")
  AND key3.taxonomy = 'post_tag'
 ";

 $pageposts = $wpdb->get_results($querystr, OBJECT);
print_r($pageposts);

This is the exact query for tags. I tested this and worked fine.
in below given you sample output

Array
(
    [0] => stdClass Object
        (
            [tag_name] => Tag1
            [tag_slug] => tag1
        )

    [1] => stdClass Object
        (
            [tag_name] => Tag2
            [tag_slug] => tag2
        )

)

Related Posts:

  1. Post meta vs separate database tables
  2. On the WordPress Admin section how do I link to submenu pages created for a plugin?
  3. Save metabox with multiple checkbox array
  4. Copy Tags from one post type to another post type
  5. How to enable users to down-vote in this simple voting counter (that uses the post meta)?
  6. How can I free up the memory used by update_post_meta?
  7. Plugin development: get_post_meta is not working [closed]
  8. Ordering posts by metadata
  9. Act on user meta updated, but only once
  10. How to check if Woocommerce Order number equals to post ID?
  11. Is there a Filter that I can use to filter the tags before they are inserted in to the database?
  12. update post meta for checkbox in the admin when inserted in the front-end
  13. 403 Error when text is pasted in Custom Metabox Textarea
  14. Saving value of a selection option in comment form as comment meta
  15. Add a Save Button to Custom Meta Box [duplicate]
  16. Is there a plugin that will allow a tag cloud to be created from any mysql field?
  17. Plugin with action ‘save_post’ needs to press publish twice on order to publish
  18. Search the product by tag or category not working
  19. Doubts about the use of metadata and how this can affect performance on WordPress
  20. update_post_meta not working in a loop
  21. Run Shortcode of post’s custom field in functions.php / Plugin
  22. Get draggable widgets on Edit Post page
  23. get_the_tags with separator control?
  24. WP nonce field checkbox prints checked=’checked’ outside input field
  25. Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
  26. Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
  27. add_action pre_term_description vs. pre_category_description
  28. Add location tag to wordpress posts
  29. Using delete_post_meta for deleting multiple selected options
  30. Get audio metadata on file upload
  31. Plugin can’t be activated [closed]
  32. Any way to update_post_meta with html content? It gets stripped and becomes empty
  33. Remove Meta-boxes (Yoast SEO plugin) [duplicate]
  34. Is there a way to add a link with add_post_meta?
  35. Adjust query on single
  36. Why is $_POST empty when saving custom Meta Box?
  37. Condition to check previous next article post title
  38. register_meta not showing custom post type metabox data in rest api
  39. Determine if term is Category or Tag
  40. Insert, update or remove data from database (usermeta)
  41. Remove tag from all posts when publishing new post
  42. Unexpected issue when using attachment_fields_to_edit filter
  43. WordPress delete mysql rows with string
  44. Dynamically getting tags in post edit screen
  45. Saving post meta
  46. Add a new tag based on the category name in the publish event
  47. Displaying Custom Post Meta
  48. Include add_post_meta in a plugin
  49. edit-tags.php in plugin admin menu hides when is the active page
  50. Access WordPress Tag Function From Modal
  51. get_the_tags($ID) is empty during publish_post callback
  52. A better way of getting draft posts that has a particular post meta using get_posts function
  53. How to run this plugin every time a post is saved?
  54. Objective Best Practices for Plugin Development? [closed]
  55. add_menu_page() with different name for first submenu item
  56. Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
  57. How to include PHP files in plugins the correct way
  58. How can I add an image upload field directly to a custom write panel?
  59. A tool to analyze rewrite rules? [closed]
  60. Difference Between Filter and Action Hooks?
  61. framework for plugin/theme options panel? [closed]
  62. Creating a table in the admin-style?
  63. How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
  64. Settings API with arrays example
  65. How to get the path to the current theme?
  66. How to make a plugin require another plugin?
  67. ajaxurl not defined on front end
  68. What process do you use for WordPress development? [closed]
  69. What’s the difference between term_id and term_taxonomy_id
  70. Should I use wpdb prepare?
  71. Why does WordPress use outdated jQuery v1.12.4?
  72. Is there any plugin development framework
  73. Is it possible to reuse wp.media.editor Modal for dialogs other than media
  74. How to add a javascript snippet to the footer that requires jQuery
  75. Enhance Media Manager for Gallery
  76. How do I create a custom role capability?
  77. How do I add CSS options to my plugin without using inline styles?
  78. How do i best handle custom plugin page actions?
  79. Adding Custom Text Patterns in the WP 4.5 Visual Editor
  80. Automatically determine minimum WordPress version required for a plugin?
  81. What is the advantage of using wp_mail?
  82. How to make a WordPress plugin translation ready?
  83. How many times will this code run? (or, how rich is grandma?)
  84. How to create an API for my plugin?
  85. Is it ever okay to include inline CSS in plugins?
  86. Plugins in symlinked directories?
  87. How to override existing plugin action with new action
  88. How to include a file using get_template_part() in a plugin?
  89. Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1
  90. How to store username and password to API in wordpress option DB?
  91. body_class hook for admin pages
  92. “Error: Options Page Not Found” on Settings Page Submission for an OOP Plugin
  93. Is it mandatory to use $wpdb->prefix in custom tables
  94. Which hook should be used to add an action containing a redirect?
  95. add_action hook for completely new post?
  96. Why does WordPress add 0 (zero) to an Ajax response?
  97. What should I use instead of WP_CONTENT_DIR and WP_PLUGIN_DIR?
  98. How to enqueue JavaScripts in a plugin
  99. In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
  100. Plugin Form Submission Best Practice
Categories plugin-development Tags plugin-development, post-meta, tags
Enable/Disable WP options programmatically
Adding Automatically To In WordPress Using Filter Referencing?

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