• kiwimaker

    (@kiwimaker)


    Hi there. I have some problems to be able to filter by author (id).

    I made a shortcode in functions.php

    /* add shortcode home posts */
    add_shortcode('post_home', 'post_home1');
    function post_home1( $atts ) { 
        ob_start();
        ?>
        <div class="wpsp-related-posts grid-container">
        <?php
            // titulo
            if(isset($atts['title'])){
                echo "<h2>".$atts['title']."</h2>";
            }
    
            // autor
            if(isset($atts['author']) && !empty($atts['author'])){
                // comprobamos texto
                $args['author']=$atts['author'];
            }
    
            $list = get_page_by_title( 'related', 'OBJECT', 'wp_show_posts' );
    
            wpsp_display( $list->ID, $args );
        ?>
    
        </div>
    
    <?php
        return ob_get_clean();
    }

    And I try to use that shortcode in a hook element

    
    <?php
    global $post;
    $author = $post->post_author;
    ?>
    [post_home author='<?php echo $author; ?>']
    

    For some reason, it’s not working and the shortcode gives me all the posts without filtering the author.

    How can I fix it?

    Thanks a lot!!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

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