Category: WordPress

Querying Dates with the WP_Query date_query

Ever need to create a query within WordPress to show posts only before or after a certain date? In a recent project – we needed to set up a page that showed only posts after January 1, 2015, and then another with posts from before that date only in order to make a clear separation between recent/archived posts. Fortunately – this was easy by using the code below:

Using “After this date… logic

$args = array(
   'date_query' => array(
      array(
         'after'    => array(
            'year'  => 2015,
            'month' => 1,
            'day'   => 1,
         ),
         'inclusive' => true,
      )
); 
$query = new WP_Query( $args );

Note: inclusive is used for after/before, whether exact value should be matched or not.

Next time you need to do a date query – make sure you check out the date_query option which makes these sorts of queries nice and easy.

Full documentation: http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters

WordPress Update: WordPress 4.1 Now Available

Happy holidays! WordPress version 4.1 is now available and offers a lot of nice improvements both on the front and back end.

For content publishers – the “Distraction-free writing” option makes authoring great content easier/less distracting.

distraction

Users now also have the option to “Log out everywhere” so if you are on a shared computer and forgot to sign out – you can go to your profile and choose “log out everywhere

WordPress 4.1 also offers introduces a new theme called “Twenty Fifteen” which is a beautiful responsive theme.

On the backend – developers now are able to easily work with more complex meta, date, and term queries, have a number of new options in the “Customizer API”, and have better control over the title tag with themes.

You can read more about the update: https://core.trac.wordpress.org/log/branches/4.1?stop_rev=30798&rev=30974

You can download WordPress 4.1: http://wordpress.org/wordpress-4.1.zip

WordPress Site Management with JetPack

With the recent update of the JetPack plugin – a new feature called “Site Management” has been added.

If you run multiple WordPress sites – the chances are – you are using the same plugins on multiple sites. If you would like to streamline plugin updates – you can now easily do so with the new “Site Management” option in JetPack.

How does this work?

  1. Update to JetPack 3.3 and enable the new feature by clicking “Activate Now” in the JetPack banner (seen above)
  2. Log in to http://wordpress.com/sites to view the sites you have registered, add more if needed.
  3. Choose the site you want to configure for plugin updates and see all plugins listed. Select each plugin to configure it (perhaps some plugins you will always want to update automatically, but others not). There are two options – Active and Autoupdates. (Active = plugin active vs. inactive) Autoupdate (auto update this plugin vs do not auto update the plugin)

While this makes managing plugin updates easier – make sure you consider quality assurance testing. Auto updates or mass updating plugins makes updating easy – but the need for quality assurance testing is still needed and should not be overlooked. Whether you have unit tests or do testing with user scripts – remember to still plan for time/effort after the updates.

Thanks to JetPack for taking this on. I look forward to playing around with this.

WordPress Update: WordPress 4.0.1 Now Available

WordPress version 4.0.1 is now available for download. This latest version of WordPress is an important security update. If your site supports automatic background updates, your site should already by up to date – or will be within the next few hours. This security update is considered critical – as there are multiple cross-site scripting issues as well as 23 bug fixes in the update. Please take a few minutes to back up your site and apply this update now.

You can read more about the update: https://wordpress.org/news/2014/11/wordpress-4-0-1/

You can download WordPress 4.0.1: http://wordpress.org/wordpress-4.0.1.zip

WordPress Update: WordPress 4.0 Available

WordPress version 4.0 is now available for download. This latest version of WordPress is full of user interface improvements that will make working with WordPress feel smoother and more refined. If you have not updated your site yet, be sure to create a backup, and then update so you can experience the improvements of 4.0

A few highlights:

  • Improved media preview
  • Embed videos, playlists by simply adding in a URL (list of all embeds supported)
  • Improved editor for all screen sizes
  • Improved plugin search and installer view
  • Language chooser (on install)
  • More powerful ORDER BY when using WP_QUERY

You can read more about the update: http://wordpress.org/news/2014/09/benny/

You can download WordPress 4.0: http://wordpress.org/wordpress-4.0.zip

WordPress Update: WordPress 3.9.2 Now Available

WordPress version 3.9.2 is an important security release and is now available for download. If you have not updated (or are not set up for automatic background updates) – take some time to backup your site and update.

You can read more about the update: https://core.trac.wordpress.org/log/branches/3.9?stop_rev=29383&rev=29411

You can download WordPress 3.9.2: http://wordpress.org/wordpress-3.9.2.zip

Helpful WordPress wp-config.php Settings

wp-config.php – one most important WordPress files, yet often overlooked. There are a number of great configuration gems you can add to your wp-config.php file to help with debugging, performance, and maintenance that I would recommend looking at if you use WordPress (there is surely something for everyone). All settings are documented: in the WordPress Codex but here are some of my favorite.

  • Specify the Number of Post Revisions
    define( 'WP_POST_REVISIONS', 3 );

    The default is set to 5 but a lower number can decrease database clutter.

  • Empty the Trash
    define( 'EMPTY_TRASH_DAYS', 15 ); // 15 days

    The default is set to 30 but if you are looking to make things tidier – you can easily lower the time between deleting items marked as trash.

  • Automatic Database Optimizing
    define( 'WP_ALLOW_REPAIR', true );

    The default is set not to optimize the database – so putting this in the wp-config will enable optimization.

  • Disable the Plugin and Theme Editor
    define( 'DISALLOW_FILE_EDIT', true );

    The default is set to allow editing. Users want the ability to edit theme and plugin files, but developers know better and know it is just a matter of time before save goes bad. Disallow it.

  • Save Queries for Analysis
    define( 'SAVEQUERIES', true );

    The default is not to save queries. As mentioned before in an earlier post this is a great way to debug and optimize WordPress.

  • Redirect Nonexistent Blogs
    define( 'NOBLOGREDIRECT', 'http://example.com' );

    If this is set when using WordPress Multisite – you can set up a redirect for the browser if the visitor tries to access a nonexistent blog so you can better control traffic.

Overall – there are a number of helpful settings available for you to explore by adding a line or two to to the wp-config.php file. It is well worth your time reviewing your site performance, needs, and data every so often to make sure your site’s performance is the best it can be. Take a few minutes to check out all the options available to you!

Focus on Your Code Not Your Environment

We are big fans of WP Engine. There are a lot of great reasons to use them for WordPress hosting – but one of the coolest services they offer is the ability to set up and use their staging area. Recently – we created a new theme and used the staging environment for all development. Since we loved it so much – we wanted to share on how to use it!

Staging Environments Made Easy

When we started the development – we simply went to our WP Admin area, clicked on one button “Copy from LIVE to STAGING” and within minutes – an email was sent letting us know it was all set up. All content, themes, plugins, settings – all the same as the live site. Since working with the live content, plugins, etc – is crucial for quality assurance – being able to do this in one simple step is a real time saver. We then were able to stage everything, adjust content, widgets, etc and then click on “Copy site from STAGING to LIVE” and viola – everything we changed was then in place on the live site.

Staging: Not Just For Theme Updates

While the staging environment was great for the new theme – it can also be extremely helpful for general content changes, plugin update testing, and general debugging. Want to test out a mobile theme or a new plugin? Click the staging button and test. If you like it – simply push your changes from staging to live with one click.

Thanks WP Engine for making this staging environment so simple! If you are a WP Engine user and have not used this feature – take a few minutes now and check it out.

WordPress Update: WordPress 3.9.1 Now Available

WordPress version 3.9.1 is a maintenance release and is now available for download. (This release fixes 34 bugs.) If you have not updated (or are not set up for automatic background updates) – take some time to backup your site and update.

You can read more about the update: http://core.trac.wordpress.org/query?status=closed&group=resolution&milestone=3.9.1

You can download WordPress 3.9.1: http://wordpress.org/wordpress-3.9.1.zip

Remove Menu Items From WordPress Admin Bar

Ever want to remove items from the WordPress Admin Bar? If yes – there is a simple way to handle this using a few steps:

  1. Identify what you want to remove.
  2. View the page source and find the CSS ID of the item you want to remove (see screenshot). Note whatever comes after “wp-admin-bar-“. Example: wp-admin-bar-dashboard – you would note “dashboard”
  3. Add the following code into your theme’s functions.php file and customize the “CSS ID” that you want to remove. (The example below will remove the dashboard link)
/**
 *  Remove Dashboard Link for subscribers
 *
*/
add_action( 'wp_before_admin_bar_render', 'sdac_custom_admin_bar' );
function sdac_custom_admin_bar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('dashboard');
}