• Added the below apply_filters in a file in my theme

    $videos_query = apply_filter('mars_main_widget_args',$videos_query,$this->id);
    $wp_query = new WP_Query( $videos_query );

    In the themes function file i have

    if( !function_exists( 'mars_widget_post_ids' ) ){
        /**
         * @param array $query
         * @param string $widget_id
         */
        function mars_widget_post_ids( $query, $widget_id ) {
            if( $widget_id == 'mars-mainvideo-widgets-5' ){
                $query['post__in'] = array( 1,4,5,6 );
            }
            return $query;
        }
        add_filter( 'mars_main_widget_args' , 'mars_widget_post_ids',100,2);
    }

    The filter is not being applied any mistake

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Why do you need to go through a filter? Why not just call mars_widget_post_ids() directly?

    If you really do need the filter, there may be an issue where the filter is applied before the callback is added. It’s hard to say without more context. $this->id looks a little suspicious without more context too. Is this in a class declaration? Or there just may be a typical bug where a variable doesn’t have the value you think it does. The usual debugging techniques will track something like that down.

    You have a typo for “apply_filters” declaration, you wrote it “apply_filter”, could this be your issue?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘add_filter not working’ is closed to new replies.