• Resolved Skoltz

    (@skoltz)


    Hello all,

    I’ve recently created a custom shortcode to retrieve custom post type (loisirs) filtered by a custom taxonomy called “categorie”
    My custom wp query works great everywhere except on the rendered automatic mail.

    The problem is, when I filter by taxonomy, the query shows no results, but as soon as i remove it, it shows all posts of the custom post type “loisirs”.

    This is really strange, here is my code:

    function mailpoet_shortcodes_custom_filter( $tag_value , $user_id) {
    
        if ($tag_value === 'dernieres_activites') {
    
            $replacement = do_shortcode('[get_latest_loisirs]');
        }
        return $replacement;
    }
    add_filter('wysija_shortcodes', 'mailpoet_shortcodes_custom_filter',10 ,2);
    // $args of custom query
    $args = array(
            'post_type' => array('loisirs'),
            'tax_query' => array(
                'relation' => 'AND',
                array(
                    'taxonomy'  => 'categorie',
                    'field'     => 'slug',
                    'terms'     => array('culture','fun','sortie'),
                    'operator'  => 'IN',
                ),
            ),
            'post_status' => 'publish',
            'order' => 'DESC',
            'orderby' => 'date',
            'offset' => 0,
            'posts_per_page' => 5,
            'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1,
        );

    when I remove this bit of code :

    array(
                    'taxonomy'  => 'categorie',
                    'field'     => 'slug',
                    'terms'     => array('culture','fun','sortie'),
                    'operator'  => 'IN',
                ),

    every thing works well, but this is not what I want :/

    https://wordpress.org/plugins/wysija-newsletters/

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom WP Query not working properly on Custom Shortcode’ is closed to new replies.