• Resolved BeingMaverick

    (@beingmaverick)


    I am writing a very simple code to list links based on category passed read from meta data of a post. If I hard code the category in the wp_list_bookmarks funct, it works fine but when i pass as a variable, it fails and shows a blank screen. below is the piece of code.

    <?php
    $category = get_post_meta($posts[0]->ID, ‘Category’, true);
    $album = get_post_meta($posts[0]->ID,’Album’,true);
    echo ($category);
    echo ($album);
    if ($category == “MusicAlbum”)
    {
    echo (“inside if”);
    wp_list_bookmarks(‘categorize=0&category_name=$album&’);
    }
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • you could try and tidy this line (excess amperand & at the end) and see if that helps:

    wp_list_bookmarks('categorize=0&category_name=$album&');

    to:

    wp_list_bookmarks('categorize=0&category_name=$album');

    or:

    wp_list_bookmarks('categorize=0&category_name='.$album);

    Thread Starter BeingMaverick

    (@beingmaverick)

    Thanks for your reply..I had tried both the above option and they dont work. The weird part is, it goes inside the if condition and outputs “inside if”, also the value of $album is displayed by echo statement, but wp_list_bookmarks does not work.

    Below is the output
    MusicAlbum3-Idiotsinside if

    If I replace $album with 3-Idiots, it works fine. So its definitely to do with $album. Does it require any escape character to understand the $ sign?? Or is it something to do with the theme(Arjuna X 1.3.8) I am using?

    Your reply is much appreciated..

    Thread Starter BeingMaverick

    (@beingmaverick)

    alchymyth the problem is resolved.
    I was being stupid by adding extra ‘ in wp_list_bookmarks

    wp_list_bookmarks(‘categorize=0&category_name=’.$album’);

    The correct format should have been,
    wp_list_bookmarks(‘categorize=0&category_name=’.$album);

    Thanks for your help and support, much appreciated.

    Just out of curiosity, what if we have 2 variables as arguments? how will that work?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_list_bookmarks fails if argument is $varname’ is closed to new replies.