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

  • Home
  • SEARCH
  • 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 8365189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:36:03+00:00 2026-06-09T12:36:03+00:00

So I’m trying to integrate a bit of WordPress with a backend. Their MySQL

  • 0

So I’m trying to integrate a bit of WordPress with a backend. Their MySQL schema isn’t too great, especially when you add in Woocommerce.

I’ve come up with the following query:

SELECT wp.* 
FROM   wp_postmeta wp
       INNER JOIN (SELECT post_id 
                   FROM   wp_postmeta
                   WHERE  ( `meta_key` = '_shipping_method' 
                            AND `meta_value` = 'free_shipping' ) 
                           OR ( `meta_key` = '_order_items' 
                                AND `meta_value` LIKE '%search%' )) a 
               ON a.post_id = wp.post_id 
ORDER  BY wp.post_id DESC

To be run on this table https://i.stack.imgur.com/qMHQp.jpg to select the right things for certain people.

Now when I var_dump this in PHP it comes out like so (truncated) – http://pastebin.com/WR3byT8k

Is there any way I can map this properly to an array so that I can use something simple like:

echo $content['_billing_first_name']; 
echo $content['_billing_last_name'];

Which would output:
John
Citizen

Keep in mind all the content is dynamic, so I can’t just use row numbers.

  • 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-09T12:36:04+00:00Added an answer on June 9, 2026 at 12:36 pm

    If you have a fixed set of meta keys you need to retrieve (not necessarily a fixed order), you can do it in the query itself by using a technique similar to a pivot table.

    SELECT 
      post_id,
      MAX(CASE WHEN meta_key = '_billing_first_name' THEN meta_value ELSE NULL END) AS _billing_first_name,
      MAX(CASE WHEN meta_key = '_billing_last_name' THEN meta_value ELSE NULL END) AS _billing_last_name,
      MAX(CASE WHEN meta_key = '_some_other_attribute' THEN meta_value ELSE NULL END) AS _some_other_attribute,
      MAX(CASE WHEN meta_key = '_another_attribute' THEN meta_value ELSE NULL END) AS _another_attribute,
      ...
      ...
    FROM wp_post_meta
    GROUP BY post_id
    

    The CASE statements determine which parameter you are pulling and assign it to a column. They are wrapped in MAX() aggregates simply to eliminate the NULLs which result when the keys don’t match, collapsing it down to a single row with columns for each attribute rather than multiple rows with mostly NULL values.

    Failing this (if your set of attributes is varies unexpectedly), you would need to iterate in code. That would be messy though.

    In PHP:

    Using PHP, if you have an array of the meta post keys you want to retrieve, you can loop over all rows and if the meta_key is one you want, store the meta_value onto an array:

    // Assumes your WP query results are already stored into the array $your_db_rows
    
    // Will hold your final processed results
    $output = array();
    // If you want only a specific set of meta_key names rather than all meta_key names
    $keys_you_want = array('_billing_first_name','_billing_last_name','_some_other_attribute');
    
    // Loops over the result set
    foreach ($your_db_rows_array as $row) {
      // If the current row holds one of the meta_key you are looking for
      if (in_array($row['meta_key'], $keys_you_want)) {
        // Put it onto the output array using the meta_key as the array key
        $output[$row['meta_key'] = $row['meta_value'];
      }
      // Otherwise do nothing...
    }
    var_dump($output);
    

    To get all meta_key, just leave out the in_array() test and the $keys_you_want array. That will store every meta_key encountered onto $output.

    // Loops over the result set for all values of meta_key, not a specific set
    foreach ($your_db_rows_array as $row) {
      // Put it onto the output array using the meta_key as the array key
      $output[$row['meta_key'] = $row['meta_value'];
    }
    var_dump($output);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

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.