Created
September 22, 2016 21:12
-
-
Save willybahuaud/cf210d94d1f8e692a1771e5ae17ae8d8 to your computer and use it in GitHub Desktop.
Update post_modified on _bbp_last_active_time update, to improve order efficiency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'updated_post_meta', 'update_post_modified_on__bbp_last_active_time_update', 10, 4 ); | |
function update_post_modified_on__bbp_last_active_time_update( $meta_id, $object_id, $meta_key, $_meta_value ) { | |
if ( '_bbp_last_active_time' == $meta_key ) { | |
$obj = get_post( $object_id ); | |
if ( 'topic' == $obj->post_type ) { | |
$obj->post_modified = $_meta_value; | |
$obj->post_modified_gmt = gmdate('Y-m-d H:i:s', strtotime( $_meta_value ) ); | |
wp_insert_post( $obj ); | |
} | |
} | |
} | |
add_filter( 'pre_get_posts', 'willy_order_topics' ); | |
function willy_order_topics( $q ) { | |
if ( $q->get( 'post_type' ) == 'topic' ) { | |
$q->set( 'orderby', 'modified' ); | |
} | |
return $q; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment