Category Archives: Programming

WordPress Logo

WordPress 3.6, Read More Links Broken

My WordPress sites updated to 3.6 pretty smoothly.

Read More links for post excerpts are not being output by functions.php.

The fix is simple. Just change … to … in the filter.

 * Add 'Read More' link to excerpts.
add_filter( 'the_excerpt', 'tsg_excerpt_read_more_link' );
function tsg_excerpt_read_more_link( $output )
    global $post;
    return str_replace(' [&hellip;]', '.. <a class="read-more" href="'. get_permalink($post->ID) . '">Read More...</a>', $output);
WordPress Logo

WordPress Pagination Breaks when Custom Posts are Included in the Query

I’ve been using All-in-One Event Calender for a recent client project. They would like to show both recent blog posts and ai1ec_event (custom) posts in one blog feed style page.

If I disable pagination (increase the limit) they all display fine, but as soon as I enable pagination I see 404 when I try to access page 3, sometimes I can get page 2 to work. You would think if pagination was not working it would 404 on page 2 every time.

Here is the query I was trying.

$wp_query =  new WP_Query(array('post_type' => array('post', 'ai1ec_event'), 'paged' => $paged));

// Proceed with the loop.

After a few days of persistent searching, I found a similar solution for custom post types. It turned out to be a WordPress 3.4 bug.

The below code needs to be added to your functions.php if you are experiencing this bug. What triggered me to believe it isn’t the plugin, was that pagination worked fine in the search result output.

 * Fixes pagination bug with WP 3.4 and the homepage when using 
 * custom post types (latest posts).
add_action( 'pre_get_posts', 'custom_query_for_homepage' );
function custom_query_for_homepage( $query )
    if( $query->is_main_query() && $query->is_home() )
        $query->set( 'post_type', array( 'post', 'ai1ec_event' ) );

Hopefully this helps a few people.

MKV Logo

Change Default Tracks in MKV Files

Matroska (.mkv) is a container format with multiple audio and subtitle tracks. It depends on your language preferences as to what tracks are selected by default. I figured out a way to batch process whole directories to change the default tracks. MKVPropEdit is the command line tool required. You can download it as part of the MKVToolNix package.

Batch Processing

Run mmg.exe or use MKVInfo with the command line to find out your track numbers. Enter the settings you desire into a batch.bat file like the below example. Run the script and watch the magic happen. It’s best to run tests on a small directory to make sure it works properly. Nothing beats watching a computer do the work for you!

@echo off
for /f "tokens=*" %%G in ('dir *.mkv /a-d /b') do (
	C:\path\to\mkvpropedit.exe "%%G" --edit track:2 --set flag-default=0
	C:\path\to\mkvpropedit.exe "%%G" --edit track:3 --set flag-default=0
	C:\path\to\mkvpropedit.exe "%%G" --edit track:4 --set flag-default=1
	C:\path\to\mkvpropedit.exe "%%G" --edit track:5 --set flag-default=0

Flynsarmy has written a Linux version of the script.

for file in "/path/to/files/"*.mkv
	echo $file
	mkvpropedit "${file}" --edit track:2 --set flag-default=0
	mkvpropedit "${file}" --edit track:3 --set flag-default=0
	mkvpropedit "${file}" --edit track:4 --set flag-default=1
	mkvpropedit "${file}" --edit track:5 --set flag-default=0