0

I am trying to create a Windows Store App using IdeaPress, which relies on the JSON API Plugin. Unfortunately requesting recent_posts returns just content up to the

<!--more--> 

tag. I'd like to display the whole post, though. Any ideas on how to do this?

This is my json code.

2

You can try this to show the full post content only in the JSON API:

function remove_more_wpse_96740($content) {
    if(get_query_var('json')){
        global $post;
        $content = preg_replace('/<!--more(.*?)?-->/','',$post->post_content);
    }
    return $content;
}
add_filter('the_content', 'remove_more_wpse_96740',1);

by targeting the json query variable and remove the <!--more--> part of the post.

If you have a custom string like <!--more But wait, there's more! -->, it will also be removed.

This part of the plugin in /json-api/models/post.php:

  function set_content_value() {
    global $json_api;
    if ($json_api->include_value('content')) {
      $content = get_the_content($json_api->query->read_more);
      $content = apply_filters('the_content', $content);
      $content = str_replace(']]>', ']]&gt;', $content);
      $this->content = $content;
    } else {
      unset($this->content);
    }
  }

is fetching the content and the check for <!--more(.*?)?--> in the content takes place in the WordPress function get_the_content().

PS: Using the method above will disable <!--noteaser--> in the JSON API, but that should be alright since you want the full post content there.

  • 1
    get_query_var('json') should be changed to get_query_var('json_route'), as otherwise it won't work any more! – vlood Jan 18 '15 at 0:25
  • 1
    Worked great for me but had to change get_query_var('json') to get_query_var('json_route') – Hans Mar 28 '17 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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