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'm trying to use an ajax function in my custom template to retrieve a post's custom fields to show a post overview. Getting the custom fields is working, but the getting the permalink isn't. I'm getting the permalink so I can link to the post. All I get back when I use get_permalink() is the first letter. Also, be noted that I'm using AJAX to return an array. I don't know if that is making the problem though.

Thank you so so so much.

Hunter

Code

function ajax_action_stuff()
{
    $post_id = $_POST['post_id']; // getting variables from ajax post

    $get_plane_custom = get_post_custom($post_id);

    $condition = $get_plane_custom['Condition'];
    $rules = $get_plane_custom['Flight Rules'];
    $manufacturer = $get_plane_custom['Manufacturer'];
    $model = $get_plane_custom['Model'];
    $price = $get_plane_custom['Price'];
    $lease = $get_plane_custom['To Lease'];
    $time = $get_plane_custom['Total Time'];
    $year = $get_plane_custom['Year'];
    $permalink = get_permalink($post_id);

    $plane_details = array("condition" => $condition, "rules" => $rules, "manufacturer" => $manufacturer, "model" => $model, "price" => $price, "lease" => $lease, "time" => $time, "year" => $year, "link" => $permalink);

    foreach($plane_details as $key => $value)
    {
        echo $value[0] . "|";
    }

    die();
}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

The value of index 'link' of the array $plane_details is a string, and thus $value[0] gives you the first letter only.

Just replace $value[0] by $value and all should be fine.

Why are you referencing the value this way, anyway?

share|improve this answer
    
$value wasn't working at all. All it returned when I was handeling it with javascript was Array –  copilot0910 Mar 11 '13 at 20:22
    
Have you checked $post_id, $get_plane_custom and $permalink for their respective value? If there is everything working as expected until you set up the array, there is (normally) no way the echo is not working (as in you said you had no access to $value). –  t f Mar 11 '13 at 20:29
    
Also, I'm referencing the value because I'm making a way to grab the custom fields and show some quick facts about a post when you click on the post in the navigation bar. –  copilot0910 Mar 13 '13 at 20:03
    
Your solution works now. Thanks so much @tf –  copilot0910 Mar 15 '13 at 15:15
    
Well ... glad I could be of some help. :) But why is it working 'now' - and not before? What did you change (in your code or mine)? –  t f Mar 15 '13 at 15:38

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.