• I am trying to return posts from a post type called “single_release_post” that has a meta tag of “u365_artist_name”. I got that to work, but I want to take it a step further and choose what that “u365-artist-name” actually returns based off which page you’re on.

    MY PROBLEM is that I want to make the value in the array (shown below) my currently viewing post title if that makes sense… lol. So for example if the post title of the page your viewing is “Jon Banks” the array value of “u365-artist-name” would be “Jon Banks”. Therefore it would return the posts from what artist name I type in my meta box from my post type “single_release_post”.

    <?php
    // Single Release Posts
    $args = array (
    'post_type'              => 'single_release_post',
    'post_status'            => 'publish',
    'pagination'             => false,
    'posts_per_page'         => '3',
    'posts_per_archive_page' => '7',
    'ignore_sticky_posts'    => true,
    'key'      				 => 'u365_artist_name',
    'meta_query'             => array(
    	array(
    	'value'     => '',
    	'compare'   => '=',
    	'type'      => 'CHAR',
    		),
    		),
    		);
    // The Query
    $single_release_artist_single = new WP_Query( $args );
    // The Loop
    if ( $single_release_artist_single->have_posts() ) {
    while ( $single_release_artist_single->have_posts() ) {
    $single_release_artist_single->the_post();
    ?>

    The above code is what I have so far on a page i’m working on here http://e9f.78a.myftpupload.com/artist/jon-banks/ As you can see the “Take Off” post should not be showing because it has a artist name of “GA” and your viewing the “Jon Banks” page.

    Does anyone know how I can return the “u365

Viewing 1 replies (of 1 total)
  • If I understand your problem correctly, you want to query the posts by post_type of single_release_post and meta_key of u365_artist_name with value of the name of currently viewing post.

    Well, you can get the current post title with get_the_title function. Then, pass this value into the meta_value filter in the WP_Query $args. For example:

    $post_title = get_the_title();
    
    $args = array(
    	'post_type'              => 'single_release_post',
    	'post_status'            => 'publish',
    	'pagination'             => false,
    	'posts_per_page'         => '3',
    	'posts_per_archive_page' => '7',
    	'ignore_sticky_posts'    => true,
    	'meta_key'               => 'u365_artist_name',
    	'meta_value'             => $post_title
    );

    I found a nice article about querying the DB using meta keys and values.

Viewing 1 replies (of 1 total)
  • The topic ‘How do I use a "PHP Function" to return an "Array value" ?’ is closed to new replies.