php - Wordpress: Get posts by tag where tag contains a name -


i working on portfolio website multiple artists, , each artist have own blog.

for each artist have own blog decided them 'tag' in posts make, on portfolio pages list posts said tags.

the name of page, name, thought using:

<?php      $args=array('posts_per_page'=>2, 'tag' => $post->post_title); $wp_query = new wp_query( $args ); ?> 

would work, doesn't seem pull results. yet when echo post title , tag both displayed same.

so next thought match tag reg expression. like:

<?php if( preg_match("/tony/i",$post->post_title)){     echo "tony";     } ?> 

but not know how work wp query.

any idea how this, or if there better way same end result?

i quite baffled exact same issue. trying display articles based on combination of first , last name, wasn't working using tag argument. ended using tag_slug__and mine. here's came with...

<?php   $original_query = $wp_query; $args = array( 'tag_slug__and' => array(strtolower($first_name) . "-" . strtolower($last_name)) ); $wp_query = new wp_query( $args ); if(have_posts()):     echo "<h3>news tagged " . $first_name . " " . $last_name . "</h3>";      while(have_posts()) : the_post();          $title = get_the_title();         $content = get_the_content();         $date = get_the_date();              //use vars suuhhhhweeeeet!    endwhile; endif; $wp_query = $original_query; wp_reset_postdata(); ?> 

the reason used tag_slug__and because tag slug lowercase tag spaces delimited -. not ideal solution, , feels hacky, work.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -