• Resolved ehsanmn

    (@ehsanmn)


    I show most viewed attachments in my site footer with this code :

                        <?php
                            $amir_query = array (
                                'range' => 'custom',
                                'time_quantity' => 1,
                                'time_unit' => 'hour',
                                'order_by' => 'views',
                                'post_type' => 'attachment',
                                'limit' => 3,
                                'thumbnail_width' => 75,
                                'thumbnail_height' => 75,
                                'stats_views' => 1,
                                'cat' => '-202',
                                'post_html' => '
                                    <div class="post"><figure class="post-thumb"><a href="{url}">{custom_thumb}</a></figure><div class="post_title"><h5><a href="{url}">{title}</a></h5></div></div>
                                ',
                                );
                                if (function_exists('wpp_get_mostpopular'))
                                wpp_get_mostpopular($amir_query);
                        ?>

    I want to exclude some attachments from this list by ids, any idea?

    my site link : https://mwallpaper.ir/?p=6544 (footer)

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @ehsanmn,

    Use the pid parameter to exclude IDs from the list, see Parameters for more details.

    Thread Starter ehsanmn

    (@ehsanmn)

    I tested that with Both the parent post ID and attachment ID, but its not working.

    I think because pid is for post_type=posts and does not work for attachments.

    for showing attachments with wpp_get_mostpopular I added a snippet code to functions.php to show items that have inherit post_status (like attachments)

    function wp8762_include_inherit_status( $where, $options ) {
    return $where . " OR p.post_status = 'inherit'";
    }
    add_filter( 'wpp_query_where', 'wp8762_include_inherit_status', 10, 2 );

    I think need a snippet code like this to add pid parameter for attachment IDs too.

    Plugin Author Hector Cabrera

    (@hcabrera)

    I think because pid is for post_type=posts and does not work for attachments.

    That’s not correct. The pid parameter works for all post types.

    Please share your updated code here so I can see if there’s something that needs adjustments.

    Thread Starter ehsanmn

    (@ehsanmn)

    this is my code :

                        <?php
                            $amir_query = array (
                                'range' => 'custom',
                                'time_quantity' => 1,
                                'time_unit' => 'hour',
                                'order_by' => 'views',
                                'post_type' => 'attachment',
                                'limit' => 3,
                                'pid' => '4346',
                                'thumbnail_width' => 75,
                                'thumbnail_height' => 75,
                                'stats_views' => 1,
                                'post_html' => '
                                    <div class="post"><figure class="post-thumb"><a href="{url}">{custom_thumb}</a></figure><div class="post_title"><h5><a href="{url}">{title}</a></h5></div></div>
                                ',
                                );
                                if (function_exists('wpp_get_mostpopular'))
                                wpp_get_mostpopular($amir_query);
                        ?>
    Plugin Author Hector Cabrera

    (@hcabrera)

    Alright, finally had time to look into this.

    Did some testing and found out that the problem is this wpp_query_where filter hook. Please change it to this and the pid parameter should work as intended:

    function wp8762_include_inherit_status( $where, $options ) {
    	$where = str_replace("p.post_status = 'publish'", "(p.post_status = 'publish' OR p.post_status = 'inherit')", $where);
    	return $where;
    }
    add_filter( 'wpp_query_where', 'wp8762_include_inherit_status', 10, 2 );
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘exclude attachments from’ is closed to new replies.