Support » Fixing WordPress » query by a custom field echo or page title

  • Resolved sheriffderek


    i have an artists page. i am retrieving a bunch of info by echo of custom fields. at the bottom of this page – i wanted to query posts only of this artists name. (recent news column… and recent events column)//// (below custom field is ‘artist’)(artist name is ‘san gabriel’)

    <?php query_posts(array('artist' => 'san-gabriel', 'showposts' => 3)); ?>

    so this works… but the key thing i’m trying to do – is keep this template ready – so that i don’t have to make separate pages for each artist… so- i’ve been trying to insert echo or the page title… (as they would be the same) to retrieve page name – that i would use to query the proper posts…

    <?php echo get ('artists_name') ?>
    <?php wp_title("",true); ?>

    both of these return the name i want (san gabriel)

    but this doesn’t work…
    <?php query_posts(array('artist' => 'wp_title("",true);', 'showposts' => 3)); ?>

    and about 10 other approaches all break the page…

    basically… i feel like if i can echo the artist name… (outside of the loop… and query posts is outside the loop… then why can’t i replace “san-gabriel” with something dynamic that is responsive to either the page title… (which is always the artist’s name) or with an echo of a custom field that is also the artist’s name????

    am i going about this all the wrong way ?

    i’ve spent at least 12 hours reading about this … i read digging into wordpress and i’ve been scouring the codex. i just want my client to be able to make pages themselves. otherwise this would be easy if i made a page for every artist…

    any ideas ?

    thank you for your time.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try this:

    <?php query_posts(array('artist' => wp_title("",false), 'showposts' => 3)); ?>

    !!!!!! thank you !!!

    		$testVar = wp_title("",true);
    		echo "$testVar";      // wp_title

    this was working – so i knew i wasn’t crazy… i thought i had chosen true because i wanted a string !!! it was the string right? not the quotes? i must have read it wrong. thanks so much for your time !!!

    <h2 class="header">upcoming shows:</h2>
    		<?php query_posts( array(
    			'cat' => 'shows',
    			"order" => 'desc',
    			'orderby' => 'meta_value',
    			'meta_key' => 'show_info_date',
    			'artist' => wp_title("",false),
    			'showposts' => 3
    			) ); ?>

    resolved !

    Actually, this was not working the way you thought:

    		$testVar = wp_title("",true);
    		echo "$testVar";      // wp_title

    To see what I mean, take out the echo. The ‘true’ parameter tells wp_title() to echo the variable, not return it, so the echo statement is echoing nothing.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘query by a custom field echo or page title’ is closed to new replies.