WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_list_bookmarks fails if argument is $varname (4 posts)

  1. BeingMaverick
    Member
    Posted 4 years ago #

    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&');
    }
    ?>

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    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);
  3. BeingMaverick
    Member
    Posted 4 years ago #

    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..

  4. BeingMaverick
    Member
    Posted 4 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic