Wordpress

Code Snippet NameSort by Category CategorySort by Category Submitted BySort by Person   Date

More Mime’s

Wordpress 04/17/11
Use this snippet to add more mime types to the wordpress media library uploader. View Code

Tags

Detach post attachment

Wordpress 04/17/11
Did a bunch of googling then gave up and wrote a query.

Use this to detach an attachment from a wordpress post. wp_delete_attachment() seems to completely delete the attached file in addition to deleting the connection.

Use this query to change the attachment parent id to 0, this will ... View Code

Tags , ,

Manual Media Library Access

Wordpress 04/17/11
Ok this is my hack to access the wordpress media library from an admin page, plugin or theme. You basically create a link to the library and pass along the post id with it, make sure the link has the appropriate thickbox attributes, and that you have enqueued thickbox.

Upon clicking the 'Insert ... View Code

Tags

Count posts in taxonomy

Wordpress 04/16/11
This wordpress sql query counts posts or custom posts in a taxonomy under multiple terms, just add more terms separated by commas where term-slug and term-slug2 are.

This is very useful because the get_terms() and get_terms_by() functions return the count of posts associated with the queried ... View Code

Tags , , ,

Get next available post id

Wordpress 04/16/11
Use this wordpress php snippet to find the next available post id, essensialy you are getting the last auto-increment id for the wp_posts table. If using this in a plugin remember that wordpress creates auto-draft posts when you go to 'Add New' so if you are planning to use this to post outside of ... View Code

Tags ,

Post Columns

Wordpress 04/13/11
Use this to add columns to the list of posts when using a custom post type. That way you can add one of your own taxonomies where the default wordpress post list displays the category column. I have not yet tested this snippet - it is from Matt, one of the other code collective administrators and ... View Code

Tags

Query for custom post taxonomy

Wordpress 03/26/11
This only works in Wordpress 3.1

Use this to create a wordpress loop to show posts that belong to a custom post type and are members of a taxonomy term. That's a mouthful but means that you can query posts by custom categories, which are taxonomies that you associate with your new custom post ... View Code

Tags , ,

Count children of a custom post

Wordpress 03/13/11
Use this php wordpress snippet to count the number of children of a post with a custom post type. Basically just pass in the id of the parent post and the custom post type and you will be returned the number of post children that belong to the parent. View Code

Tags , ,

Apply template to all child pages

Wordpress 03/08/11
I was having trouble recursively accessing page children using $post->post_parent, it looks like this only returns the immediate parent of a post.

This function will check all of the posts with a parent ID of 6215 and then apply a template to them, in this case its page-kyle.php

This routine will ... View Code

Tags

Custom post icon

Wordpress 03/05/11
Use this wordpress snippet to change the custom post type icon in the user interface. View Code

Tags

Excerpt Read More Link

Wordpress 02/28/11
Use this wordpress filter function combo to add a read more link at the end of your excerpts. View Code

Tags ,

Get current admin color scheme

Wordpress 02/26/11
This wordpress conditional will provide you with the current default admin color scheme. It will allow you to style your dashboard widgets according to the current back end theme. The gray theme is called 'fresh' and the blue theme is called 'classic'.

Enjoy, this was easier that I thought. View Code

Tags

SQL Count Posts in Category

Wordpress 02/25/11
This was yet another tough one to figure out, but worth it. This custom query allows you to count the number of private posts in a category. Its easy to count published posts using a variety of wordpress template tags but there was no easy and lightweight way to pull it off that I could find. ... View Code

Tags ,

Disable WP 3.1 admin bar

Wordpress 02/24/11
Use this filter to remove the Wordpress 3.1 front end admin bar. Wordpress 3.1 has a new feature that shows an admin bar at the top of your blog pages when you are logged in. This feature is great but it is good to be able to turn off the wordpress 3.1 admin bar or admin menu. View Code

Tags

Easy plugin options

Wordpress 02/23/11
I wrote this snippet to cut down on lines of code in my wordpress plugins. On home made admin pages that have a ton of get_option() calls and many variables this routine makes organizing the option names easy.

Just set your default option names and values in the array $plugin_options, then the ... View Code

Tags ,

Is Admin Conditional

Wordpress 02/17/11
I just discovered some interesting phenomenon concerning ajax combined with wordpress. I am writing a plugin that loads a php page using ajax. Said page loads wordpress by including the file 'wp-load.php' and is displayed within the wordpress admin interface.

If you try to check the is_admin() ... View Code

Tags , ,