A
A
Anton2015-10-02 20:22:43
Programming
Anton, 2015-10-02 20:22:43

How to get content of posts in wordpress?

Hello! There is a plugin for Wordpress that displays a table with a schedule. Now only the title of the posts is displayed there, but I also need to display their description (content). Here is the code itself:

$event = get_posts(array(
          'name' => $events_array[$i],
          'post_type' => 'events',
          'post_status' => 'publish',
          'numberposts' => 1
        ));
        $events_array_id[] = $event[0]->ID;
    }

I tried to do this, but the $content variable for some reason returns an empty value.
$eventin = get_posts(array(
              'name' => $events_array[$i],
              'post_type' => 'events',
              'post_status' => 'publish',
              'numberposts' => 1
            ));
            $events_array_id[] = $event[0]->ID;
        }

        foreach ($eventin as $event) : setup_postdata($event);
        the_content(); // returns the content normally
  $content = apply_filters('the_content', $content);
  $content = str_replace(']]>', ']]>', $content);
endforeach;

I would be very grateful for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2015-10-02
@DigitalEmotions

...
 $content =$event->post_content;
 $content = apply_filters('the_content', $content);
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question