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 4567236
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:54:07+00:00 2026-05-21T18:54:07+00:00

When I just let one WHERE and remove the other it returns me the

  • 0

When I just let one WHERE and remove the other it returns me the correct result. When I have it as is it does not display anything. How can I write correctly my logic below?

My aim is to display only the result who satisfy the “extra1 = $value1 and extra2 = $value2 and extra3 = $value3.”

I read somewhere that I have to add the addslashes. What is the use of it?

$value1 = addslashes($_GET['extra1']);
$value2 = addslashes($_GET['extra2']);
$value3 = addslashes($_GET['extra3']);

$theposts = $wpdb->get_results("SELECT post_title FROM {$wpdb->posts}
WHERE ID IN
(
   SELECT DISTINCT post_id
   FROM {$wpdb->postmeta}
   WHERE meta_key = 'extra1' AND meta_value = '$value1'
   WHERE meta_key = 'extra2' AND meta_value = '$value2'
   WHERE meta_key = 'extra3' AND meta_value = '$value3'

)");
  • 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-05-21T18:54:08+00:00Added an answer on May 21, 2026 at 6:54 pm

    If your database supports intersections then you can do this:

    SELECT post_id
    FROM {$wpdb->postmeta}
    WHERE meta_key = 'extra1' AND meta_value = '$value1' 
        INTERSECT
    SELECT post_id
    FROM {$wpdb->postmeta}
    WHERE meta_key = 'extra2' AND meta_value = '$value2'
        INTERSECT
    SELECT post_id
    FROM {$wpdb->postmeta}
    WHERE meta_key = 'extra3' AND meta_value = '$value3'
    

    That will give you all the post_ids that have extra1/value1, extra2/value2, and extra3/value3.

    If you don’t have INTERSECT (such as, AFAIK, MySQL), you can try HAVING:

    SELECT post_id
    FROM {$wpdb->postmeta}
    WHERE meta_key = 'extra1' AND meta_value = '$value1'
       OR meta_key = 'extra2' AND meta_value = '$value2'
       OR meta_key = 'extra3' AND meta_value = '$value3'
    GROUP BY post_id
    HAVING COUNT(*) = 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So let's say I have just-a.domain.com,just-a-domain.info,just.a-domain.net how can I remove the extension .com,.net.info ...
So I have an object graph, let's just say it's an order. You have
Let's say I want a way to display just the the center 50x50px of
Let's say: <div> pre text <div class=remove-just-this> <p>child foo</p> <p>child bar</p> nested text </div>
So let's say I have two different functions. One is a part of the
I'm not really sure to understand completely the factory pattern. Let's say I have
This title is not fully depicted what I mean, but I just can't come
Before I start with the real question, let me just say that I might
I'd like to just create a thread, then call CloseHandle immediately and let the
just a quick question: I am a CS undergrad and have only had experience

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.