Forums

Getting results from WP database (3 posts)

  1. tobydecks
    Member
    Posted 1 year ago #

    Hi WP-ists....

    I writing a simple plugin for WordPress, albeit slowly.

    I've got it writing to the database, but it's getting the info out that I can't seem to do

    In my brain, this should work:

    function displayCatImg(){
            global $wpdb;
            $getImg = $wpdb->query("SELECT imageurl FROM wp_blogcathead WHERE id = '7'");
                echo $getImg;
    }

    Basically, it should pull a URL from a new table in the WP database.

    Do I need to use foreach?
    There is only one value being taken from the database though.

    Should I be using something other than echo?

    Anyone? Class? Anyone?

    Cheers
    Toby

  2. tobydecks
    Member
    Posted 1 year ago #

    Ahh $wpdb->query did it :)

    Now, another question is can I get the current category for the post I'm viewing and store it as a variable?

    Thanks

  3. tobydecks
    Member
    Posted 1 year ago #

    The category ID number, rather than the name.

    I have `$category = get_the_category();
    $catid = $category[0]->cat_name;`
    That gave me the name of the category, but I want the ID number instead.
    Can I adapt the above to give me the number rather than the name?

    Fanks

Topic Closed

This topic has been closed to new replies.

About this Topic