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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:16:11+00:00 2026-06-08T21:16:11+00:00

I’m using WordPress and trying to create a view to make reviewing and analyzing

  • 0

I’m using WordPress and trying to create a view to make reviewing and analyzing my resort data a little easier. Resort data is stored in the post_meta table in WordPress and referenced in a custom post type known as “resorts”. The following query gives me the result set I want to parse:

SELECT a.id, a.post_type, a.post_title, b.post_id, b.meta_key, b.meta_value
FROM alpinezone_postmeta b
INNER JOIN alpinezone_posts a ON a.id = b.post_id
WHERE a.post_type = "resorts" 

What I want to do with this result set is have each unique meta_key of a set I define become a column and then each row should be a unique b.post_id (or a.id), which corresponds to an individual resort’s record.

So ultimately I end up with:

post_title |   phone_num      | state         |
resort1    |   800-200-1111   | Vermont       |
resort2    |   800-200-2222   | New Hampshire |
resort 3   |   800-200-2323   | Maine         |

Basically …… I’m not that great at MySQL so trying to figure out the best way to handle this. I do have a list of all the meta_key I want to place into columns, there are 36 of them capturing a range of information.

EDIT: Some more detail.

Current Structure – shows what table it comes from as well

*alpinezone_posts   alpinezone_postmeta alpinezone_postmeta*
post_title          meta_key            meta_value
----------------------------------------------------------------
sugarloaf           snow_phone          888-234-2222
sugarloaf           vertical_feet       2300
sugarloaf           site_url            sugarloaf.com
wachusett           snow_phone          888-111-2222
wachusett           vertical_feet       1000
wachusett           site_url            wachusett.com

These two tables are joined on post_id from table alpinezone_postmeta and id from table alpinezone_posts.

Only want results where the post_type in table alpinezone_posts is = “resorts”

How I want it to look in new view

post_title  snow_phone      vertical_feet   site_url
-------------------------------------------------------
sugarloaf   888-234-2222    2300            sugarloaf.com
wachusett   888-111-2222    1000            wachusett.com
  • 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-08T21:16:13+00:00Added an answer on June 8, 2026 at 9:16 pm

    You want to use is a cross-tabulated table or pivot table with “GROUP BY” like this example here: http://en.wikibooks.org/wiki/MySQL/Pivot_table

    You need to use something other then SUM() for strings though… like MAX():
    http://forums.mysql.com/read.php?20,75357,75367#msg-75367

        SELECT p.post_title AS post_title,
             MAX(IF(m.meta_key='phone_num',m.meta_value,0)) AS phone_num,
             MAX(IF(m.meta_key='state',m.meta_value,0)) AS state
        FROM alpinezone_postmeta m
        INNER JOIN alpinezone_posts p ON m.post_id = p.id
        WHERE p.post_type = 'resorts'
        GROUP BY m.post_id`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build

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.