Your cart is currently empty!
remove the access filters for category sidebar posts
—
by
Hi guys,
I currently have a snippet of code that allows a user to see the excerpt and images of posts on pages (this also includes the sidebars of those pages). In addition I added to the code to allow posts to be viewed on category pages however the posts and excerpts for the sidebar don’t display. Can you help me to allow the sidebar posts and excerpts to display on the category pages?
Below is the snippet of code I’m using:
// Add an action to pre_get_posts
add_action(‘pre_get_posts’, ‘my_pre_get_posts’);
function my_pre_get_posts() {
// If the unsubscribed user is looking at any of the page’s listed the user will be able to view the list of post excerpts
if ( is_page(‘affairs-of-the-nation’) || is_page (‘home-phoenix-blue’) || is_page (‘last-refuge’) || is_page (‘fit-to-print’) || is_page (‘high-society’) || is_page (‘scenes’) || is_page (‘moneybags’) || is_page (‘hot-water’) || is_page (‘funnies’) || is_page (‘top-stories’) || is_page (‘profile’) || is_page (‘young-blood’) || is_page (‘foreign-frolics’) || is_category (‘issue-1’) || is_category (‘issue-2’) ) {
// Remove the Groups_Post_Access filters
remove_filter( ‘posts_where’, array( ‘Groups_Post_Access’, ‘posts_where’ ), 10, 2 );
remove_filter( ‘the_posts’, array( ‘Groups_Post_Access’, ‘the_posts’ ), 1, 2 );
remove_filter( ‘get_the_excerpt’, array( ‘Groups_Post_Access’, ‘get_the_excerpt’ ), 1 );
remove_filter( ‘the_content’, array( ‘Groups_Post_Access’, ‘the_content’ ), 1 );
remove_filter( ‘posts_where’, array( ‘Groups_Restrict_Categories’, ‘posts_where’ ), 10 );
remove_filter( ‘get_pages’, array( ‘Groups_Restrict_Categories’, ‘get_pages’ ) );
remove_filter( ‘the_posts’, array( ‘Groups_Restrict_Categories’, ‘the_posts’ ), 1 );
remove_filter( ‘get_the_excerpt’, array( ‘Groups_Restrict_Categories’, ‘get_the_excerpt’ ) );
remove_filter( ‘the_content’, array( ‘Groups_Restrict_Categories’, ‘the_content’ ) );
}
}
Thanks guys I hope this makes sense 🙂
Comments
8 responses to “remove the access filters for category sidebar posts”
Thanks George I appreciate it
Hi Aengus,
This is why i asked you what you are using to display the post/pages excerpt in the sidebar. 🙂
I will definitely have a look and let you know.
Kind regards,
George
hey George looks like what i thought worked actually didn’t. when a user who doesn’t have full access signs in the posts, images and excerpts disappear. I tired adding to the code I used to restrict categories on specific pages. However the posts in the sidebar continue to not display.
// If the unsubscribed user is looking at any of the page’s listed the user will be able to view the list of post excerpts
if ( is_page(‘page-name-1’) || is_page (‘page-name-2’) || is_page (‘page-name-3’) || is_page (‘page-name-4’) || is_page (‘page-name-5’) || is_page (‘page-name-6’) || is_page (‘page-name-7’) || is_page (‘page-name-8’) || is_page (‘page-name-9’) || is_page (‘page-name-10’) || is_page (‘page-name-11’) || is_page (‘page-name-12’) || is_page (‘page-name-1’) || is_category (‘category-1’) || is_category (‘category-2’) ) {
// Remove the Groups_Post_Access filters
remove_filter( ‘posts_where’, array( ‘Groups_Post_Access’, ‘posts_where’ ), 10, 2 );
remove_filter( ‘the_posts’, array( ‘Groups_Post_Access’, ‘the_posts’ ), 1, 2 );
remove_filter( ‘get_the_excerpt’, array( ‘Groups_Post_Access’, ‘get_the_excerpt’ ), 1 );
remove_filter( ‘the_content’, array( ‘Groups_Post_Access’, ‘the_content’ ), 1 );
remove_filter( ‘posts_where’, array( ‘Groups_Restrict_Categories’, ‘posts_where’ ), 10 );
remove_filter( ‘get_pages’, array( ‘Groups_Restrict_Categories’, ‘get_pages’ ) );
remove_filter( ‘the_posts’, array( ‘Groups_Restrict_Categories’, ‘the_posts’ ), 1 );
remove_filter( ‘get_the_excerpt’, array( ‘Groups_Restrict_Categories’, ‘get_the_excerpt’ ) );
remove_filter( ‘the_content’, array( ‘Groups_Restrict_Categories’, ‘the_content’ ) );
}
}
Is it possible to include widgets in the above code, for example I tried is_active_widget (‘widget-id’) and the_widget (‘widget-id’) but neither worked. Is there a plugin widget tag that can be used?
Any help would be appreciated… its a real humdinger! 🙁
Thanks
A
Ok that’s great!
Thanks!
Hey George,
I managed to get it to work. no need to support this ticket on my behalf
By the way I asked a question previously regarding what the code snippet accomplishes and I was told it wasnt supported yet. See below:
http://www.itthinx.com/topic/sidebar-post-excerpt-and-image-not-displaying/
The sidebar is part of the theme. I just created a page that allowed a sidebar and assigned posts to a sidebar based on categories. Im not using a plugin to display sidebar the custom snippet above allows the sidebar posts to display (for non users) until they’re clicked, once this is done the non registered user will be directed to the subscription registration page.
Any help on getting the sidebar excerpt and image to display on the category pages?
Hi Aengus,
How do you display post and page excerpts in sidebar so far? Do you use a plugin or your custom snippet?
BTW that’s a very interesting feature you have achieved so far.
Kind regards,
George