Support » Developing with WordPress » Custom SQL Query In Page

  • Hi Guys,

    Right, I need to make a few custom pages on my wordpress blog, where I can query some new database tables I have added to the database.

    Basically I want to output on the first page, a list of car manufacturers (Audi, Alfa, Ford….) which links into another page which will show all the models of the selected manufacturer.

    Now I have all this set up in two databases already, makes, and models.

    So what would I use to connect to these tables in the database, and output the query’s im after.

    I take it you wont use the usual
    mysql_query("SELECT * FROM car_make ORDER BY make")



Viewing 7 replies - 1 through 7 (of 7 total)
  • Anyone able to help?

    Cheers been looking all over for that

    Where is your site? I am trying to do a simple car site for a Park and Sell that I am starting up. I need custom tables, and I need to be able to query and display them. Also want to access carfax. I am used to using Visual Developer and have ZERO experience with this.

    Any help is appreciated.
    Randy Pruit

    Simple example :

    global $wpdb; 
                        $sql="SELECT * FROM my_table";
                        $posts = $wpdb->get_results($sql);
                        foreach ($posts as $post)

    I hope that could help you


    Hi guys!

    I created a custom post with register_post_type, which contains capability_type parameter with ‘page’ value and custom-fields property in supports array.

    I created a new post (my custom post type) and added a custom field for this post with these values:
    Custom field name: SAMPLE_KEY
    Custom field value: MY_VALUE

    I want to get this page by custom field value and name.
    I have tried this:

    $feature_query=new WP_Query();

    The $features array was empty.
    What’s wrong in my code?

    Many thanks!



    Have you thought about using post types? If so, it’ll be an easy way of creating page structures, meta value, and taxonomy relationships. If not, what shaan1974 is the best route, use the $wpdb object.

    How are you going to be structuring the pages though, as far as hierarchy? If you have experience with shortcodes, you should wrap up your query into a shortcode and then call it from within post or page content – that would be the most modular way of doing it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom SQL Query In Page’ is closed to new replies.