Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to work this function in wordpress theme the way where I can get value only what I want and not all to gather. I am not much familiar with using array in function so I need you expert help to make it works and I would really appreciate that.

Here is my code

function gallery_artist($arg=null, $arg2=null, $arg3=null){

    global $png_gallery_meta;
    $png_gallery_meta->the_meta();

    $gallery = get_post_meta(get_the_ID(), $png_gallery_meta->get_the_id(), TRUE);

    $gallery_value = $gallery['image_artist'];
    $artist_info = $gallery_value;

    $string = $artist_info;
    $artist = substr($string, 0, stripos($string, "/") );

    // getting first name and last name from user id
    $author_first_name = get_userdata(basename($string))->first_name;

    $author_last_name = get_userdata(basename($string))->last_name;

    $author_full_name = $author_first_name . ' ' . $author_last_name;

    $user_id = '<a href=" ' . get_author_posts_url(basename($string)) . ' " title="more submissions of ' . $author_first_name .' '. $author_last_name . ' " >' . $artist . '</a>';


    $arg = $author_first_name;      
    echo $arg;

    $arg2 = $author_last_name;      
    echo $arg2;

    $arg3 = $user_id;
    echo $arg3;     

}

After than I want to use this function to get any value I want and not unnecessary to render all three to gather. Means if I want only first name than I pass value only for that and it will render only first name so on..

Here how I want to use something. but you can suggest any code and type of function I have no issue.

<?php call_user_func_array('gallery_artist', array('first_name','last_name','artist_id') ) ?>

Big Big thanks to you all..

share|improve this question
add comment

1 Answer

There's wp_list_pluck() to get certain fields out of arrays or objects:

$object = new StdClass();
$object->foo = 'Hi!';
$object->bar = 'Yo!';

$array['foo'] = 'Hi!';
$array['bar'] = 'Yo!';

$result_obj = wp_list_pluck( $object, 'foo' );
var_dump( $result_obj );
// Result:
string (3) Hi!

$result_array = wp_list_pluck( $array, 'bar' );
var_dump( $result_array );
// Result:
string (3) Yo!
share|improve this answer
    
Thanks a lot kaiser I will try and get back to you –  pixelngrain Aug 7 '12 at 17:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.