ACF Recent Posts Widget

Description

ACFRPW adds a new widget to the Appearance -> Widgets -> ACF Recent Posts Widget. Most of the fields are quite obvious, you can choose from a set of settings to display the posts from.
Each setting alters the amount and type of posts listed in the sidebar.

Excerpt display, its word limit, its readmore text (occurs only if the amount of words exceeds the limit)

Custom HTML to display before the loop

Custom HTML to display after the loop

Custom HTML to display before each posts. It supports custom meta keys and ACF fields

Custom HTML to display after each posts. It supports custom meta keys and ACF fields

Custom HTML to display for no posts found

Custom and default CSS

Custom HTML templates

ACF supported fields

The plugin has been written and tested with ACF 4 (Free). Since version 4.1.5 ACF Pro is also supported,
but there’s no guarantee to the code – it’s a Beta phase and will be kept as long as ACF Pro will not have any bigger
differences between the ACF Free.

The plugin supports the following ACF fields:

Text

Textarea

Number

E-mail

Password

Wysiwg Editor

Image

File

No other fields have been tested and are supported at the moment.

Shortcode

From version 4.4 the plugin supports shortcode embeds. Given the amount of options and their specific names (as in shortcode attributes) the shorcode builder has been introduced
see 7th and 8th screenshots for the reference.

You’ll see a popup once clicked on ACFRPW button which gives one an ability to automatically set up the shortcode code for you. The rest follows all of the options specified here.

To use the shortcode one needs to have the WordPress editor enabled for the current page / post type. In case it was disabled (say via ACF) the button won’t appear.

Creating Custom Templates

From version 4.3 the plugin supports custom templates. To make usage of these one needs to make a copy of all the files found
in the acf-recent-posts-widget/templates directory and copy them over to the active template directory to acfrpw subdirectory.
The approach is similar to the way WooCommerce plugin works and has it’s drawbacks. With every new feature the files may be outdated.

Similarly to the widget template files, a separate, custom markup can be created for the shortcode build post listing. Copy the acf-recent-posts-widget/template files
to acfrpw-blog directory created inside your active theme directory.

Template files

There are 3 main template files:

loop-after.php (which displays the markup after each of the posts and closes the markup container)

loop-before.php (which displays the markup before each of the posts and opens the markup container)

loop-inner.php (which is enqueued for each of the posts separatelly and contains the markup of every single post)

Usage

The usage is quite advanced hence each template file contains a quite detailed documentation on how to use it.

First of all the template files mustn’t have the global variables removed. Each of these variables stores the widget settings, which are then used to generate the code.
Second of all the variable names are unobvious, loop-inner.php template file contains a list of all the names used, which are then extracted and available as php variables.

Different template per widget / sidebar

The templates allow one to adjust the markup of each single widget. One needs first to verify the widget id used, which may then be referenced.
The variable which stores the widget id is $acf_rpw_args[‘widget_id’]. Dumping the value in the template is the best way to find out which automatic id has been created for your widget.

The best way to handle the templates is to learn from their code. My personal suggestion is to copy over the templates to the current theme and work directly on them, doing one change at a time.
The templates require learning curve to use and there’s no single answer to everyones problem.

Complex usage

This section covers plugin complex usage for advanced user willing to have more control over the behavior of the plugin as well as explains uncommon functionalities.

Using the HTML textarea fields

These sections might not be obvious. The HTML or text before / after the whole loop setting is an area where you can specify custom HTML markup to be added before / after the whole posts list.
The HTML or text before / after each post is an area where you can not only specify custom HTML, but you are also given an ability to print any meta key or certain ACF fields (see ACF supported fields)

Meta Key Name / ACF Usage

These fields need to be wrapped inside the {meta name} or {acf field_name} tags (which are similar to shortcodes). The plugin will then parse these fields and print their according value. Say we have a custom ACF field of type text, for which the Field Name is “text”.
To print its value one has to use [acf text] inside the befoe / after each post textarea. A similar solution applies to the meta key.

Meta Value Usage

The Meta Value field supports an array of elements, so that all of the meta_compare parameters could be used. To do so, please specify the two parameters separated by semicolon, for instance: 1234;12345.
The plugin will convert these into an array and apply the proper operation for the two. Whatsmore the [date] shortcode can be used here. It takes the timestamp paramater as an argument, which is required – the possible arguments are the same as for
the function described here: http://php.net/manual/pl/function.strtotime.php. For instance [date +1 day] would generate the tomorrow date in “Ymd” format.
This can be used with custom meta field date.

Plugin Filters

The are several filters that can be used to enchance the plugin programatically:

‘acf_rwp_query’ which gives one the ability to filter the query applied to each widget.

‘acp_rwp_before’ which gives on the ability to filter the Front End output of the plugin before each post. There are two hooks attached here already which allow usage of the [acf] and [meta] shortcodes.

‘acp_rwp_after’ which gives on the ability to filter the Front End output of the plugin after each post. There are two hooks attached here already which allow usage of the [acf] and [meta] shortcodes.

Sponsors

Screenshots

ACF Field Name placement (found under Custom Fields section with ACF enabled)

First widget screen

Second widget screen

Third widget screen

Shortcode button

Shortcode creator screen

Custom templates placement

Installation

This section describes how to install the plugin and get it working.

Upload and unpack acf-widget.zip to the /wp-content/plugins/ directory

Activate the plugin through the ‘Plugins’ menu in WordPress

Drag and Drop the ACF Recent Posts Widget to the sidebar area

FAQ

Does the Plugin require Advanced Custom Fields?

No it doesn’t. Some functionalities will be missing though and a notification will be shown to the user on Plugins dashboard page.

What ACF version does it support?

The plugin supports the latest ACF 4.X.X version, currently ACF 5 is in Beta and not fully supported. However the plugin should work fine as long as there won’t be much differences between the two versions. If you want to get rid of the notice see: https://wordpress.org/support/topic/acf-5-compatibility-2

Does the Widget support author display?

No it doesn’t. We’re considering this as an update.

Does the Plugin support shortcodes, or custom posts function?

Yes, the plugin does support shortcodes since version 4.4.

Does the Widget come with any pre made classes to wrap the HTML with?

No it doesn’t.

The widget styles are messy and the thumbnail doesn’t adjust its position ?

This plugin does exactly what it's meant to do. If you're looking to create custom feeds of custom post-types, custom taxonomies, etc. using your custom fields, this is the only plugin you need. The fantastic support is a plus too!