WordPress.org

Ready to get started?Download WordPress

Forums

Custom SQL Query In Page (8 posts)

  1. Jamz
    Member
    Posted 3 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")

    Thanks

    James

  2. Jamz
    Member
    Posted 3 years ago #

    Anyone able to help?

  3. GRAQ
    Member
    Posted 3 years ago #

  4. Jamz
    Member
    Posted 3 years ago #

    Cheers been looking all over for that

  5. RandyPruit
    Member
    Posted 3 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.
    Thanks
    Randy Pruit

  6. shaan1974
    Member
    Posted 3 years ago #

    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

  7. mudlee
    Member
    Posted 2 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();
    $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!

  8. Anders
    Member
    Posted 2 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

Tags

No tags yet.