WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $wpdb Inner Join (4 posts)

  1. everyeurocounts
    Member
    Posted 1 year ago #

    I am trying to create a array of postdates where the post meets a custom taxonomy criteria (location) this will also be modified by a form element (will be using Ajax hopefully) but im stuck on creating the array.

    Basically using INNER JOIN to match the two tables and select the postdate from wp_posts where the taxomomy id = 3 (this links to another table with the text format of the taxonomy name).

    $fdates = $wpdb->get_results("SELECT post_date FROM wp_posts INNER JOIN wp_term_realtionships
    		ON wp_terms_relationships.object_id=wp_posts.object_id
    		WHERE wp_terms_relationships.term_taxonomy_id = 3");

    it just returns array() using print_r function.
    Localhost so no example :( Thanks in advance to anyone who can help me!

  2. catacaustic
    Member
    Posted 1 year ago #

    Look at the codes page for WPDB and use the error handling functions:

    http://codex.wordpress.org/Class_Reference/wpdb#Show_and_Hide_SQL_Errors

    When I try to run that query I get a few errors:

    • You've spelt wp_term_relationships in the INNER JOIN.
    • You've got the same table name wrong again in the ON and WHERE clauses (the 's' on wp_terms_ is not supposed to be there).
    • The wp_posts table doesn't have a column of object_id. it's ID.

    Any time you get errors like this you need to turn on your error reporting and do some debugging. If you'd do that you'd have found these errors in a couple of minutes. :)

  3. everyeurocounts
    Member
    Posted 1 year ago #

    thats great thank you, ill have a look at this later :)

  4. everyeurocounts
    Member
    Posted 1 year ago #

    Actually got it thanks a mill! Ill update the error reporting :)

Topic Closed

This topic has been closed to new replies.

About this Topic