RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Display Future Scheduled Posts in WordPress

Display Future Scheduled Posts in WordPress

Providing your readership with a list of scheduled posts is an effective means of cementing yourself in their minds. By giving them a sneak peak at your future content they are, anecdotally, more inclined to come back for more. This article will provide you with the necessary shortcode to render a list of scheduled posts. There are a few options that alter the way in which the information is presented.

This is a complete rewrite of a function that formerly resided on Internoetics (although it looks nothing like the old one). It's been rewritten to more closely align with WordPress best practice. Note: The little squares I've plastered on the screen are my own just to break up the page for readability.

The Result

For the first example, we'll print scheduled articles from all authors in all categories - ascending in date (most recent first). The shortcode of [future will render the following list:

■ ■ ■

  • Updated AI-Supported Website Comparison Engine on Your WebsiteJuly 23, 2200

■ ■ ■

If you're reading this at a point when there aren't any scheduled posts, the list will look as follows  (the image link includes the excerpt text).

In the example above I've list all future scheduled posts. To limit the number to just the next three that are written by me I'll use [future number="3" author="1" description="0" format="jS F Y, g:iA"]. I've enabled the short excerpt with description="1", and I've altered the format in which the date will be returned. The author="1" is my WordPress user ID. The result.

■ ■ ■

  • Updated AI-Supported Website Comparison Engine on Your Website23rd July 2200, 4:00PM

    … Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate…

■ ■ ■

In the final examples we'll display the list in a narrow box to emulate what it might look like if styled in a sidebar.

Coming soon on BeliefMedia
  • Updated AI-Supported Website Comparison Engine on Your Website23rd July 2200, 4:00PM

Our next 5 scheduled articles. See them all here.

The full list of attributes that'll alter the appearance of your list are detailed below.

WordPress Shortcode

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

1
<?php 
2
/*
3
 Display Future Scheduled Posts in WordPress
4
 http://www.beliefmedia.com/wordpress-future-posts
5
*/
6
 
7
function beliefmedia_future_posts($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'status' => 'future',
11
    'author' => false,
12
    'category' => false,
13
    'orderby' => 'date',
14
    'order' => 'ASC',
15
    'format' => false, /* jS F Y, g:iA */
16
    'description' => false,
17
    'remove' => false,
18
    'words' => 15,
19
    'number' => false,
20
 
21
    /* Style */
22
    'headingstyle' => false,
23
    'datestyle' => false,
24
    'textstyle' => false,
25
 
26
    /* Style */
27
    'cache' => 3600 * 6,
28
 
29
  ), $atts);
30
 
31
 $transient = 'bmfp_' . md5(serialize($atts));
32
 $cachedposts = get_transient($transient);
33
 
34
 if ($cachedposts !== false) {
35
 return $cachedposts;
36
 
37
 } else {
38
 
39
    global $post;
40
 
41
    /* If styles aren't defined */
42
    if ($atts['headingstyle'] === false) $atts['headingstyle'] = 'font-weight: bold;';
43
    if ($atts['datestyle'] === false) $atts['datestyle'] = 'font-size: 0.9em;';
44
    if ($atts['textstyle'] === false) $atts['textstyle'] = 'font-size: 0.9em;';
45
 
46
    /* Generally use this shortcode for future posts */
47
    $post_status = explode(',', $atts['status']);
48
 
49
    $args = array(
50
        'post_type' => 'post',
51
        'post_status' => $post_status,
52
        'orderby' => $atts['orderby'],
53
        'order' => $atts['order'],
54
    );
55
 
56
    /* Limit authors? */
57
    if ($authors !== false) $args['author__in'] = $atts['author'];
58
 
59
    /* Limit number of posts? */
60
    $args['posts_per_page'] = ($atts['number'] !== false) ? $atts['number'] : '-1';
61
 
62
    /* Specific categories? */
63
    if ($atts['category'] !== false) $args['cat'] = $atts['category'];
64
 
65
    /* Query */
66
    $pages = new WP_query($args);
67
 
68
    /* Build result */
69
    if ($pages->have_posts()) :
70
 
71
        $output = '<ul>';
72
 
73
        while ($pages->have_posts()) : $pages->the_post();
74
 
75
            /* By default your WP time format is used */
76
            $date = ($atts['format'] !== false) ? get_the_date($format = $atts['format']) : get_the_date();
77
 
78
            /* If displaying excerpt */
79
            if ($atts['description'] !== false) $excerpt = trim(str_replace($atts['remove'], '', get_the_excerpt()));
80
 
81
            if ( ($atts['words'] !== false) && ($atts['description']) ) $excerpt = wp_trim_words($excerpt, $num_words = $atts['words'], $more = null);
82
            $output .= '<li><span style=&quot;' . $atts['headingstyle'] . '&quot;>' . get_the_title() . '</span> &mdash; <span style=&quot;' . $atts['datestyle'] . '&quot;>' . $date . '</span>';
83
            if ($atts['description'] !== false) $output .= '<p><span style=&quot;' . $atts['textstyle'] . '&quot;>' . $excerpt  . '</span></p>';
84
            $output .= '</li>';
85
 
86
        endwhile;
87
        $output .= '</ul>';
88
 
89
    else :
90
 
91
        $output = '<p><ul><li>No future posts scheduled yet.</li></ul></p>';
92
 
93
    endif;
94
 
95
   /* Set transient data */
96
   set_transient($transient, $output, $atts['cache']);
97
   return $output;
98
 
99
   /* Reset query */
100
   wp_reset_postdata();
101
 
102
   }
103
 
104
}
105
add_shortcode('future', 'beliefmedia_future_posts');

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Shortcode Attributes

author

By default all authors are returned. To include only specific users, list their IDs in a comma delimited list (id="1,2,5"). To remove authors, prefix their ID with a minus sign (id="-4,-6").

category

T list only specific categories, list them as such: category="1,4,7" To exclude a category, prefix the category with a minus sign.

orderby

The orderby list is quite extensive and is listed on the WordPress codex website . The primary means of ordering is by date (default).

order

The order list designates the ascending or descending order of the list. Either ASC or DESC.

format

The format applies to the fomatting of the returned date. Review options on WP Codex or the PHP Manual .

description

The description applies to excerpt. False by default, use description="1" to display excerpt text.

remove

If you choose to use the description, you can remove certain text (usually applies to tweet text and such that are injected into your post content).

words

Refers to the number of words returned in the excerpt. The teaser is 15 words by default... you don't want to give too much away.

number

The number of posts to return. Returns all scheduled articles by default.

headingstyle

The heading style. Bold by default.

datestyle

The style applied to the date. Font size is 0.9em by default.

textstyle

The style applied to the description (excerpt) text. Font size is 0.9em by default.

cache

The period to cache your result. Defaults to 4 hours.

Considerations

  • The function will return any post types (published, drafts, etc) but we'll publish additional shortcodes designed specifically for that purpose to avoid unnecessary complexity.
  • More on WP Query here .

Download


Title: Display Future Scheduled Posts in WordPress (WP Plugin)
Description: Displays future scheduled posts in a WordPress posts or page with shortcode.
  Download • Version 0.2, 2.1K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (1.4K)    

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment