Custom SQL Query In Page (8 posts)

  1. Jamz
    Posted 5 years ago #

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



  2. Jamz
    Posted 5 years ago #

    Anyone able to help?

  3. GRAQ
    Posted 5 years ago #

  4. Jamz
    Posted 5 years ago #

    Cheers been looking all over for that

  5. RandyPruit
    Posted 5 years ago #

    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

  6. shaan1974
    Posted 4 years ago #

    Simple example :

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

    I hope that could help you


  7. mudlee
    Posted 4 years ago #

    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!

  8. Anders
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.