• Hi,

    Im working on specific project for my client.
    They got their own database with products on mySQL server (images/title/meta data). They use it for their company system.

    They want big website with lots of posts and pages but they also want to display their products online. I dont want to import them into WP database ‘cos data in DB are always changing.

    So if I create custom post type “products” is there any chance to extend WP_QUERY to query posts from different database and use results as standard WP post object?

    Thank you.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    No, WP_Query relies on the WP DB connection through the global $wpdb object, there’s no way to FROM a table through a different connection. AFAIK you cannot even FROM a different DB’s table even in mySQL.

    It’s not a big problem connecting to a different DB and running queries on it, then merging the results with WP_Query results, provided the results are structured the same way. I suspect they are not even structured the same, which is the real problem.

    You have a significant DB organization challenge that warrants careful consideration. I see two major approaches. One is to code product queries such that the final results array is structured exactly like a WP_Query array. The issue here would be ensuring that post IDs in the WP DB can never conflict with IDs assigned to products.

    The other is to go ahead and import the data and the resulting WP DB becomes the one that is constantly updated. The current product DB is no longer used. Or alter the product DB so that it functions as a WP DB. The difference is just semantics. This is really what you should do, but I realize it’s easier said than done. How your client interfaces with the new DB structure will be different, even if there is an interface outside of WP.

    There are some good e-commerce plugins available that make organizing products easy. It doesn’t matter if the site is actually selling products or not, it’s the product organization that we’re after. It’ll obviously be different than what they are doing now, but it could be an improvement. We almost all resist change, but change is often for the better.

Viewing 1 replies (of 1 total)
  • The topic ‘Extending wp_query’ is closed to new replies.