Jump to content
xisto Community
imjjss

How To Run A Left Join Query To Get Coulums In One Table? on wordpress postmeta table

Recommended Posts

Hello,
I have data saved in wordpress postmeta table, each post_id has some meta_keys, the table looks like this:

-------------------------------------post_id |  meta_key   | meta_value  |------------------------------------------   1	  | project_id	|	1			  |------------------------------------------   1	  |  height		 |	50			|------------------------------------------   1	  |  width		  |	100		  |------------------------------------------   2	  | project_id	|	2			  |------------------------------------------   2	  |  height		|	50			 |------------------------------------------   2	  |  width		 |	100		   |------------------------------------------

Now I need to query all the meta_keys and their value. (I don't need query_posts, I need the meta data only)

I tried the following code, but can't get the results I need:

$query = <<<QUERYSELECT  project_id.post_id, height.meta_value,width.meta_valueFROM $wpdb->postmeta project_idLEFT JOIN  $wpdb->postmeta height			on height.post_id = project_id.post_id			and height.meta_key = 'height'LEFT JOIN  $wpdb->postmeta width			on width.post_id = project_id.post_id			and width.meta_key = 'width'WHERE	   project_id.meta_key = 'project_id'ORDER BY	project_id.meta_value+(0) ASCQUERY;

The code get all projects, each project has 3 keys and their value-- one post_id, one meta_key, one meta_value, that's not what I want. I want one post_id with all meta_keys and their value.

Would anybody kindly spend time to help me on this?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.