• Resolved jonathandsimmons

    (@jonathandsimmons)


    So I’m a bit of a newb to php and diving in pretty hard core so please forgive what I’m sure may be many mistakes.

    I’m have a MU install and custom_options page users fill out. My goal is display indiviual values form that custom options from a number of user on the parent domain. Which means I can’t use get_site_options or get_option as those are relative to the site your on.

    My research led me to $wpdb
    So the goal will be to perform a query based on a user id or blog id (not sure which yet?), capture the custom_options entries I’m looking for and display them anyway I desire on the homepage.

    I am good with finding the user id or specifying the blog id form the user id I’m pretty sure I can work that out.

    My problem is how to query that options DB.

    I have this:
    $testing = $wpdb->get_results( “SELECT FROM $wpdb->options WHERE option_name = ‘$allowedthemes'” );
    print_r($testing);

    but this is giving me an output of:
    Array ( )

    rather than showing me the content of the array.

    I don’t want the whole array I want just a particular variable which I could work out if the array would ouput.I’ve also tried get_var instead of get-results but when I change get_results to get_var the query breaks.

    If I’m in over my head let me know.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Instead of print_r( $testing ), use var_dump( $testing ).

    Thread Starter jonathandsimmons

    (@jonathandsimmons)

    So I just tried this. I made sure was on a user site as I know I’m not yet specifying a user or blog in the query (don’t even know if I will be able to?). I’ve also switched to something more obvious for the option_name so the code is now

    <?php  $testing = $wpdb->get_results( "SELECT FROM $wpdb->options WHERE option_name = '$siteurl'");
    var_dump($testing);
    ?>

    but that just gave me:
    array(0) { }

    rather than the site name. Thoughts?

    Thread Starter jonathandsimmons

    (@jonathandsimmons)

    The weird thing is I know the query is working. If I remove the WHERE and everything after it outputs the desired table. Something is going wrong when I try to specify a particular option_name.

    any ideas what I’ve got wrong in the code?

    Thread Starter jonathandsimmons

    (@jonathandsimmons)

    ok so I got it to show me the array properly after realizing I never declared the output type. So now a clean version of my code is:

    $testing = $wpdb->get_results( "SELECT * FROM $wpdb->options WHERE option_name = 'siteurl'", OBJECT_K);
    print_r($testing);

    which results in:

    Array ( [0] => Array ( [option_id] => 1 [blog_id] => 0 [option_name] => siteurl [option_value] => https://examplesite.com/ [autoload] => yes ) )

    can anyone tell me how I can assign this values to a new variable?

    I tried:

    $testing = $testing['option_value'];

    but that did not work.

    Try changing $wpdb->get_results to $wpdb->get_row (this will return only 1 row of results).

    Also, you really should look into some PHP resources. These questions are much more related to PHP than WordPress.

    Thread Starter jonathandsimmons

    (@jonathandsimmons)

    Thanks tim, I’m moving on to some php tutorial site and forums. I appreciate your help though.

    Thread Starter jonathandsimmons

    (@jonathandsimmons)

    Using get_row fixed my issue and I was able to assign it the he variable with my above mentioned method. Thanks for the help guys.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Retrieve a particular value from the options database of an mu user.’ is closed to new replies.