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")

    Thanks

    James

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.
    Thanks
    Randy Pruit

    Simple example :

    global $wpdb; 
    
                        $sql="SELECT * FROM my_table";
    
                        $posts = $wpdb->get_results($sql);
    
                        print("<ul>");
                        foreach ($posts as $post)
                        {
                            print('<li>'.$post->FIELD1.'|'.$post->FIELD2.'<br/>');
                             print('</li>');
                        }
                        print("</ul>");

    I hope that could help you

    Shaan

    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();
    $features=$feature_query->query(‘meta_key=SAMPLE_KEY&meta_value=MY_VALUE’);

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

    Many thanks!

    Anders

    (@seananders1227)

    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.