php - ajax loading wordpress content removes linebreaks/paragraph tag -
i'm having issue ajax loading wordpress content jquery. works great, except line returns aren't being parsed. it's being pulled in json, , stuck 2 different divs.
jquery code:
$('.load').on('click',function(e){ e.preventdefault(); var person_clicked = $(this).attr('id'); $.post('/load.php', { id:person_clicked, callback:'person' } ) .done(function(data) { alert(data); $('.page_tagline').html(data.title); $('.left_content').html(data.content); scrolltoelement($('#hero')); }); return false; });
load.php:
<?php /* send json */ header("content-type: application/json", true); require('../../../wp-load.php'); ?> <?php query_posts('p='.$_post['id']); $post = $wp_query->post; ?> <?php if (have_posts()) : the_post(); ?> <?php $returned = array( 'title' => get_the_title(), 'content' => get_the_content(), ); ?> <?php echo json_encode($returned); ?> <?php endif;?>
when alert out, content looks if paragraph breaks in there. there's definite spacing between paragraphs. when lands in div it's giant run-on sentence.
also, when load spacing there. tried removing json part of ajax, , loading whole thing div, , spacing remains sure json thing (as far can tell). when doing this, code outputs /r/n/r/n new paragraph should be, wordpress does.
any ideas on how can make json retain paragraphs?
you don't automaticly conversion rowbreaks p-tags function wpautop() isn't run.
filter on the_content. if want get_the_content() have same formating the_content() need pass thorugth filters:
apply_filters('the_content',get_the_content())
Comments
Post a Comment