Title: Problem with add_filter function
Last modified: August 18, 2016

---

# Problem with add_filter function

 *  Resolved [shardick](https://wordpress.org/support/users/shardick/)
 * (@shardick)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/problem-with-add_filter-function/)
 * 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)

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/problem-with-add_filter-function/#post-650694)
 * 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](https://wordpress.org/support/users/shardick/)
 * (@shardick)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/problem-with-add_filter-function/#post-650732)
 * 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.

## Tags

 * [add_filter](https://wordpress.org/support/topic-tag/add_filter/)
 * [apply_filters()](https://wordpress.org/support/topic-tag/apply_filters/)
 * [join](https://wordpress.org/support/topic-tag/join/)

 * 2 replies
 * 2 participants
 * Last reply from: [shardick](https://wordpress.org/support/users/shardick/)
 * Last activity: [18 years, 7 months ago](https://wordpress.org/support/topic/problem-with-add_filter-function/#post-650732)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
