WordPress.org

Ready to get started?Download WordPress

Forums

How can I call a function into another function? (5 posts)

  1. microtag
    Member
    Posted 6 years ago #

    How can I call a function into another function?

    Example:

    <?php
    query_posts('tag=one');
    ?>
    show only post with tag one...but if tag is a variable?

    How insert <?php single_tag_title(); ?> instead of one ???

    If try:

    <?php
    query_posts('tag=<?php single_tag_title(); ?>');
    ?>

    I've get an error..
    How can I resolved it?

    Thanks

  2. Michael Torbert
    WordPress Virtuoso
    Posted 6 years ago #

    An argument can't be a function, but it can be a variable. I'm not exactly sure what you're trying to do, but if you can store the return value of one function as a variable, and then use that in your parameters.
    I don't know if this would be a solution for you or not, just based on the one line of code.

  3. Michael Torbert
    WordPress Virtuoso
    Posted 6 years ago #

    Well that's not exactly true, an argument can be a function, but not the way you're doing it.
    Why do you have an extra <?php and ?>... does query_posts() step out of PHP?

  4. microtag
    Member
    Posted 6 years ago #

    I've many post with tags..
    In sidebar, into archive page, I would insert this code:

    <?php
    query_posts('tag=iphone+video&showpost=10');
    ?>

    Works correctly...show only post with tags iphone and video..but if I would change "iphone" with current tags I've many problems...

    Ex:

    <?php
    query_posts('tag=<?php single_tag_title(); ?> +video&showpost=10');
    ?>

  5. diego018
    Member
    Posted 5 years ago #

    ok, so how do you place the variable in the function?

    i have converted the argument into a variable:
    <?php $current_tag = single_tag_title("", false); ?>
    now
    <?php single_tag_title(); ?>
    is
    $current_tag
    am i right?

    now how can i add that variable to this function (replacing the tag "coldplay" with "$current_tag")

    <?php
    echo '	';
    if ( is_tag(coldplay) ) {
     ' &raquo;  '; include(TEMPLATEPATH . '/articles/coldplay.php');
    }
    echo '
    ';
    ?>

    how is the final code?
    please help me thanks! i have been hours trying to solve it

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags