• Resolved shardick

    (@shardick)


    Hi,

    i was playing with add_filter to create a plugin that permit to list my posts in an mandatory order (date independent).

    So, i’m adding this filter

    add_filter(‘posts_join’, ‘wp_postorder_join’);

    function wp_postorder_join() {
    global $wpdb;
    return ” LEFT JOIN ” . $wpdb->postmeta . ” as postorder on postorder.post_id = ” . $wpdb->posts . “.ID and postorder.meta_key = ‘post_order’ “;
    }

    Everything works fine but when i try to list posts by taxonomy item, the join settep up by wordpress creating the query is replaced by my join and query runs in error.

    I dont know if this is a bug or not but i have solved like this:

    at wp-includes\query.php line 1185

    $where = $where . apply_filters(‘posts_where’, $where);
    $join = $join . apply_filters(‘posts_join’, $join);

    So, i can mantain original join and adding a custom join.

Viewing 2 replies - 1 through 2 (of 2 total)
  • There is no problem here. The ‘proper’ way to go about this is to design your plugin like so:

    function wp_postorder_join($join) {
    	global $wpdb;
    	$join .= " LEFT JOIN " . $wpdb->postmeta . " AS postorder ON postorder.post_id = " . $wpdb->posts . ".ID AND postorder.meta_key = 'post_order' ";
    	return $join;
    }
    Thread Starter shardick

    (@shardick)

    very nice!

    thanx a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with add_filter function’ is closed to new replies.