Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8776727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:07:27+00:00 2026-06-13T19:07:27+00:00

In the table below, the meta keys logo_ID and show_logo are associated with each

  • 0

In the table below, the meta keys logo_ID and show_logo are associated with each other based on the post_id field. How do I get the value of logo_ID for rows which have a show_logo of 1 using only mysql?

post_id  meta_key     meta_value
-------  -----------  ----------
262      logo_ID      263       
262      show_logo    0         
260      logo_ID      261       
260      show_logo    1         
258      logo_ID      259       
258      show_logo    1         

If it looks familiar it’s because this is from the WP postmeta table. I’m using $wpdb to query the db so everything has to be in mysql (no WP functions anywhere).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:07:28+00:00Added an answer on June 13, 2026 at 7:07 pm

    You can join the wp_postmeta table to itself, specifying the value you want in the WHERE clause.

    SELECT pm2.post_id, pm2.meta_key
    FROM wp_postmeta pm1 
    JOIN wp_postmeta pm2 
        ON pm2.post_id = pm1.post_id AND pm2.meta_key = 'logo_ID'
    WHERE pm1.meta_key = 'show_logo' AND pm1.meta_value = 1
    

    If you are dealing with a lot of data, this is fairly fast as it will use indexes on the wp_postmeta table. You can JOIN the wp_postmeta more if you want to get other values as criteria as well, or the wp_posts table to get the other post fields.

    SQL Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the mysql table below has two columns. how do i select only those rows
I have a table as below. I have to populate the Amount field using
Hello i'm currently using a table to input values into a custom meta field.
The table below works well. However, I am trying to pass $row[username] along as
Would following the table below be the best way of determining the access type
i have the table below <tr id=group_1>...</tr> <tr id=el>...</tr> <tr id=el>...<tr> <tr id=group_2></tr> <tr
In the table below, the entire cells are hyperlinks. How can I make just
for the table below tenant_id | status_id ---------------------- 3 | 6 --------------------- 5 |
I'm currently working on a dynamic table below: echo '<table border=1>'; echo '<tr align=center
I need help with the SQL ORDER BY clause. In my table below I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.