How Do I Programmatically Force Custom Permalinks with My Theme?

To fully enable permalinks, you also need to ensure that .htaccess is also created. To do that, you need to set an option and flush the rules with a Boolean. global $wp_rewrite; //Write the rule $wp_rewrite->set_permalink_structure(‘/%postname%/’); //Set the option update_option( “rewrite_rules”, FALSE ); //Flush the rules and tell it to write htaccess $wp_rewrite->flush_rules( true ); … Read more

get_attached_media() returns empty array if media file already used by another post

I ran into this problem and ended up creating a basic function to extract the “attached” media by URL from the body of the post (in my case a post of type document, but it should work with any kind of post): function get_first_link_url($post_id) { $content = get_post_field(‘post_content’, $post_id); if ($content == null) { return … Read more

How to add a 2nd “featured image” to a post?

This plugin has worked for me in the past: http://wordpress.org/extend/plugins/multiple-post-thumbnails/ Or you could create a custom field – Advanced Custom Fields makes this very easy (and for the end user too): http://plugins.elliotcondon.com/advanced-custom-fields/ This could be integrated by using the traditional ‘featured image’ as the slider image – ie leaving <?php the_post_thumbnail(); ?> or equivalent in … Read more