Skip to content

Instantly share code, notes, and snippets.

@willybahuaud
Created September 22, 2016 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willybahuaud/cf210d94d1f8e692a1771e5ae17ae8d8 to your computer and use it in GitHub Desktop.
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
<?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