• Resolved Snaphaan

    (@snaphaan)


    I need to extract the data saved in my widgets from wp_options for comparisons and other uses. As far as I understand the data needs to be un-serialized and that is the function of get_option().

    But I can’t seem to do anything with the data.

    The following code seems simple enough:

    $text_widgets = get_option( 'widget_suidlanders_advertensies' );
    	echo var_dump($text_widgets);
    
    	foreach ( $text_widgets as $widget ) {
    		extract( $widget );
    }

    The var_dump() throws out the following:

    array (size=2)
      2 =>
        array (size=3)
          'title' => string 'Titel' (length=5)
          'text' => string 'Teks' (length=4)
          'textarea' => string 'Teks Area is hier		' (length=19)
      '_multiwidget' => int 1

    How am I suppose to utilize this to make a comparison? If ($this == $that) etc.

    [Moderator Note: No bumping. If it’s that urgent, consider hiring someone instead.]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    get_option() unserializes the data for you, as is evidenced by var_dump outputting an array and not a string. The array with title, text, textarea will be in one of the $widget instances inside the loop. When you extract that array, it is equivalent to this:

    $title = 'Titel';
    $text = 'Teks';
    $textarea = 'Teks Area is hier		';

    So to do a comparison inside the loop after $widget is extracted, you just do something like this:
    if ('Titel' == $title ) echo 'Titel found in title!';

    Thread Starter Snaphaan

    (@snaphaan)

    That was a big help in pushing me in the right direction. Thank you!!

    After reading up a bit more I assigned the values to variables like so.

    foreach ( $text_widgets as $widget => $value) {
    $title = $value['title'];
    }

    and now I can work the rest of my magic!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Unserialize serialized data in wp_options’ is closed to new replies.