Title: How do I use a &quot;PHP Function&quot; to return an &quot;Array value&quot; ?
Last modified: August 22, 2016

---

# How do I use a "PHP Function" to return an "Array value" ?

 *  [urban365](https://wordpress.org/support/users/urban365/)
 * (@urban365)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/how-do-i-use-a-php-function-to-return-an-array-value/)
 * 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/](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)

 *  [Rastislav Lamos](https://wordpress.org/support/users/lamosty/)
 * (@lamosty)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/how-do-i-use-a-php-function-to-return-an-array-value/#post-5923774)
 * 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](http://www.advancedcustomfields.com/resources/how-to-query-posts-filtered-by-custom-field-values/)
   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.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [code](https://wordpress.org/support/topic-tag/code/)
 * [Coding](https://wordpress.org/support/topic-tag/coding/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [PLEASE](https://wordpress.org/support/topic-tag/please/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [Rastislav Lamos](https://wordpress.org/support/users/lamosty/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/how-do-i-use-a-php-function-to-return-an-array-value/#post-5923774)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
