Why WordPress?

Before I dive into all the great things about WordPress, why you should build your site with it (or switch if you’re on one of the other platforms)… let’s start with a few stats:

Now that that’s out of the way…

(more…)

WordPress: Display all images attached to a post/page

NOTE: Nov 20, 2013 – This post has been updated to include more examples from the comment thread. View the updated post here »

You’ve probably struggled with the default output of the WordPress gallery shortcode. It’s OK. We all have. By default, WordPress wraps the entire gallery in a div, and then further wraps the images in dl & dt tags.

There are a few, excellent WordPress image gallery plugins that address gallery shortcode styling (File Gallery Plugin), as well as the invalid XHTML code (Cleaner Gallery Plugin). These plugins work great for many things, but they also add a lot more functionality.

If all you want to display is a simple list of all the image attachments that are attached to a particular page/post, and you just want the img tags, there’s a much easier way to do it.

(more…)

WordPress: Search Custom Post Type(s)

I’ll admit, the default WordPress search engine is not the most robust. However, there are a few ways to customize it. One of the most common requests is, “How do you limit a WordPress search to a custom post type?” Below, I explain how to display results for one post type, as well as multiple custom post types.

Limit WordPress Search Results to 1 Custom Post Type

If all you want to do is limit your WordPress search to a single custom post type, add the following line of code inside the <form> on your searchform.php template.

<input type="hidden" name="post_type" value="your-posttype-here" />

Depending on how you have customized your searchform.php template, it should look something like this:

<form id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
	<input type="hidden" name="post_type" value="your-posttype-here" />
	<label class="assistive-text" for="s">Search</label>
	<input id="s" class="field" type="text" name="s" />
	<input id="searchsubmit" class="submit" type="submit" name="submit" value="Search" />
</form>

Limit WordPress Search Results to Multiple Custom Post Types

If you want to limit your search to more than one custom post type, you have to go about it a slightly different way.

Add the following lines of code in the same place in your searchform.php file:

<input type="hidden" name="post_type[]" value="post_type_one" />
<input type="hidden" name="post_type[]" value="post_type_two" />

Replace post_type_one and post_type_two with the name of your custom post type.

This works mainly because WordPress’ WP_Query object can handle the post_type parameter as an array.

Thanks to John Sparrow for this code snippet.