• calling this function with jQuery to load content into page with ajax

    problem is the $post array isn’t getting established and therefore I cannot retrieve values such as $post->ID

    any ideas why the_content works but the $post array is not there?

    ‘function post_loader_show_post ( ) {
    if ( have_posts() ) :
    while ( have_posts() ) :
    the_post();
    ?>
    <div <?php post_class() ?> >
    <h1 class=”title”><?php the_title();?></h1>
    <?php
    $subK = ‘subtitle’;
    $subT = get_post_meta($post->ID, $subK, TRUE);
    if($subT != ”) {
    echo $subT;
    }
    ?>
    <?php the_content();?>
    </div>
    <?php
    endwhile;
    die();
    endif;
    }’

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jay.weeks

    (@jayweeks)

    got it, had to add
    global $post; after the_post(); for some reason ?? not sure why this object wasn’t established without this intervention

    any ideas?

    Because you’re inside a function. In PHP, variables inside functions are purely local unless declared otherwise.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘ajax content’ is closed to new replies.