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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:48:30+00:00 2026-06-18T20:48:30+00:00

I am working on extracting and displaying data from a WordPress DB to a

  • 0

I am working on extracting and displaying data from a WordPress DB to a mobile app for a customer and I am having a little trouble refining this query to be most efficient.

In wordpress, there are three tables that link the data I need to access
1. wp_posts – in this table there is the main post title, it’s published status and the post type.
2. wp_postmeta – this table has all supplemental info related to the post id in the above table.
3. wp_p2p – this table has links to all the parent-child posts and their relationship.

Because of the volume of data in these tables, the query I currently have takes about 13 seconds to run, could you please take a look at this sqlfiddle and let me know what I could look at to improve it? The query in it’s current form is not the end result, but improving it will improve my end result. I also need to add a search field on the “name” in the wp_postmeta table.

http://sqlfiddle.com/#!2/0e9e0/1

Any direction is appreciated, thank you!

  • 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-18T20:48:31+00:00Added an answer on June 18, 2026 at 8:48 pm

    If I understand correctly, you’re looking for only child posts, in which case, the query below should be much faster:

    SELECT wp_posts.id,  post_title, post_status, post_type
    FROM wp_posts
    JOIN wp_postmeta ON (wp_posts.id = wp_postmeta.post_id)
    LEFT JOIN wp_p2p ON (wp_posts.id = wp_p2p.p2p_from)
    WHERE `post_status`='publish' AND `post_type`='merchant' 
    AND wp_p2p.p2p_from IS NULL
    GROUP BY wp_posts.id
    

    This query will be optimized to find where a match doesn’t exist in the p2p table so that part will be much faster than how you’re currently doing it. It looks like you can also remove the JOIN on wp_postmeta since you don’t use it at all. Removing that JOIN would also make the GROUP BY redundant and removing it could help the performance a little. Removing the GROUP BY would also be a good practice since strictly you can’t select non-aggregate fields that aren’t in the GROUP BY clause, but MySQL provides for this functionality so the query will still work either way.

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

Sidebar

Related Questions

I'm working on extracting data from a SQL Server database with a latin_1 character
I am working on a project that requires reading text files, extracting data from
I am working on manipulating/extracting data from well-formed HTML in one of our legacy
I am extracting data from a forum. My script based on is working fine.
So I'm extracting the lines that I want from this larger file using this
Language : C++ I am working on Bit Packing (Extracting the required bits from
I have been extracting information from the iTunes App Store for the past couple
I'm currently working on a digital project and I have to analyze data from
I'm working to develop a small system for extracting content from web pages (I
I am having trouble extracting a zip-archive on a windows machine. I am currently

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.