Displaying posts

The WP Social Wall WordPress API documentation.

Getting the plugin class instance

We use one single function the get the API instance of the plugin. This can be done with the following function call.

$wpSocialWall = get_wp_social_wall_api();

Getting posts

Getting posts from the API is also just one simple function call. You can do this by getting the instance and calling the following function.

$posts = get_wp_social_wall_api()->getPosts();

This function supports an array of arguments. The arguments supported in the function call are limit, page & platform. A fully filled argument list call can look something like this.

$posts = get_wp_social_wall_api()->getPosts([

  ‘limit’ => 10,

  ‘page’ => 1,

  ‘platforms’ => [

    ‘facebook’, ‘instagram’, ‘twitter’

  ]

]);

Looping over the posts

After getting the posts it’s just an easy loop over the posts results array. Here is an example of a twig file that loops over the results.

{% for socialPost in socialPosts %}

  {% include ‘partial/social-post.twig’ with { socialPost: socialPost } %}

{% endfor %}

Or with just pure PHP it can look something like:

<?php foreach ($socialPosts as $socialPost) { ?>

  <p><?php echo $socialPost->platform; ?></p>

<?php } ?>