Archive for January, 2014

Remove Duplicate Posts from Custom WordPress Loop

Tuesday, January 14th, 2014

How to: WordPress Remove Duplicate Posts Loop

In WordPress, sometimes you want to run multiple custom queries, but you don’t want the same post to appear in each query. This can happen when you want to feature posts in different categories, but a post may exist in multiple categories, so it is possible for the post to appear under each category.

This article describes the proper way to remove duplicate posts from multiple queries, so that the proper number of posts appear, and the same post won’t appear multiple times.

Find the file you want to edit, and before your custom query, declare a new variable:

/** This is where we are going to store the post ID's for the posts we've already displayed
 * Note: this resets the variable, so be sure to only include it once.
 * Also, if it's included in a template part, beware it may get called multiple
 * times, which would allow posts to be duplicated
$do_not_duplicate = array();

Then, inside your loop, add each post ID to the $do_not_duplicate variable:

$query = new WP_Query($args);
if ($query->have_posts()) {
    while($query->have_posts()) {
        // Add the post ID to the array
        $do_not_duplicate[] = get_the_ID();

        // Your code to display the post goes here...

Finally, to bring it all together, when you are preparing your next custom query arguments, pass in the array into the post__not_in parameter, like so:

$args = array (
    'post_type'        =>  'post',
    'posts_per_page'   => '10',
    'post__not_in'     => $do_not_duplicate
$query = new WP_Query($args);

And there you have it! The posts from the second custom loop will not include any duplicates from the first post.

And, you can string this together for multiple custom queries. Just keep adding post ID’s to the variable, and using the post__not_in parameter, and you will be all set. (Note: do not put the first line in the code again, otherwise it will reset the variable, and you will begin getting duplicates again! This line: $do_not_duplicate = array(); resets the variable, so only declare this once at the top of the file).

ACG gets Responsive Web Design for Mobile Devices

Monday, January 13th, 2014

As a web development company, it only seems right that our website should have a responsive web design.

Allowing us to display the same content, utilizing the same markup, images, and styles, we simply added the appropriate media queries, made a few tweaks here and there, and now the site is responsive. It will display properly regardless of the device, or browser window size.

The only weakness in the way that we styled this is that you must be viewing it in Internet Explorer 8 or higher for it to respond properly. But, so long as you are using a browser at least 960 pixels wide, it will still display even in Internet Explorer 8.

While we tested on a variety of mobile platforms, one of the cool tools we used is the Web Developer toolbar for Firefox, which allows us to see the rendering in a variety of sizes quickly, in one page. Check out the screenshots below.

Responsive Web Design for Mobile

Firefox Web Developer tool allows us to see mobile versions of our Responsive Web Design

Responsive Web Design for Tablets

Firefox Web Developer toolbar allows us to see tablet views for our Responsive Web Design