Don’t show post at all in loop …
-
Hello,
I have 2 kind of memberships … guest and premium … I have enabled individual post protection addon. And, for example, I want hide completly post (in loop, and evrywhere) protected by premium mode … in fact, I want to hide all posts (with no invitation to login) protected post in premium when a guest user is logged …
Is-it possible ?
thx a lot for your help …
-
Hi @theeponymus,
Hope you’re doing well ??
Post protection in Membership 2 should hide posts from the loop by default if you protect them, is this not working properly for you?
Could you share URL where we can see this in action and tell us which posts should be protected?Only way to protect posts but still keep them in loop would be by using URL Protection add-on and protecting direct URL of single post.
Cheers,
PredragHi Predrag,
if you look at first ebook : Fisher Irving, Illusion de la stable” … is a protected post.
thx for your help
FulgenceHello Fulgence,
Can you check if on add-ons list you also don’t have “Category Protection” enabled with “Individual Posts”?
I tested on my site and with “Individual Posts” and protected post, they are not showing on the posts loop.
Could you also check if you switch to Default WordPress theme like twenty seventeen they are still showing?
kind regards,
KasiaHi Kasia,
You are right /// thx a lot /// it ‘s due to my own theme …
I have :
$args = array(
‘post_type’=> ‘post’,
‘order’ => ‘ASC’,
‘posts_per_page’ => $my_nb,
‘post_parent’ => 0,
‘auteur’ => $my_auteur,
‘category_name’ => $my_cat,
);
$the_query = new WP_Query( $args ); // etc…as shortcode for my theme in home page … can you please tell me what king of variables must i specify to hide protected content ?
thx for your help …
Fulgence
Hi Fulgence,
Could you paste your entire shortcode in pastebin.com or similar site and share the URL here so we can have a closer look at this?
Cheers,
Predraghi Predag,
function ebooks_func( $atts ) {
$a = shortcode_atts( array(
‘auteur’ => ”,
‘selection’ => ”,
‘tag’ => ”,
‘cat’ => ”,
‘nb’ => ”,
), $atts );
// return “{$a[‘auteur’]}”;
$my_auteur = $a[‘auteur’];
$my_cat = $a[‘cat’];
$my_nb = $a[‘nb’];
$txt = “”;
$args = array(
‘post_type’=> ‘post’,
‘order’ => ‘DESC’,
‘posts_per_page’ => $my_nb,
‘auteur’ => $my_auteur,
‘category_name’ => $my_cat,
);
$the_query = new WP_Query( $args );
$txt .= “<div class=’grid’>”;
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$txt .= ‘<div>’;
// $my_post_id = $post->ID;
$txt .= “<a href='”;
$txt .= get_permalink();
$txt .= “‘>”;
$txt .= get_the_post_thumbnail($the_query->post->ID);
$auteur = strip_tags( get_the_term_list( $the_query->post->ID, ‘auteur’, ”, ‘, ‘, ” ));
$categories = get_the_category();
$my_cat=””;
if ( ! empty( $categories ) ) { $my_cat = $categories[0]->slug;}
$txt .= ‘<h3 class=”‘.$my_cat.'”><span class=”cover_author”>’;
$txt .= preg_replace(‘/(.*) /’,'<i>$1 </i>‘,$auteur).”</span><br>”;
$title = get_the_title($the_query->ID);
//$my_title = str_replace(“|”,”</span><br><span class=’cover_author’><i>”,$title);
//echo preg_replace(‘/(.*) /’,’$1 </i>‘,$my_title);
$txt .= “<span class=’cover_title’>”.$title;
$txt .= ‘</span></h3>’;
$txt .= ‘</div>’;
}
}
wp_reset_postdata();
$txt .= “</div>”;
return $txt;
}
add_shortcode( ‘ebooks’, ‘ebooks_func’ );Hi @theeponymus,
Can you please use pastebin as suggested above or at least paste the code wrapped inside Code tag as the current one has messed up formatting?
Cheers,
Predragfunction ebooks_func( $atts ) { $a = shortcode_atts( array( ‘auteur’ => ”, ‘selection’ => ”, ‘tag’ => ”, ‘cat’ => ”, ‘nb’ => ”, ), $atts ); // return “{$a[‘auteur’]}”; $my_auteur = $a[‘auteur’]; $my_cat = $a[‘cat’]; $my_nb = $a[‘nb’]; $txt = “”; $args = array( ‘post_type’=> ‘post’, ‘order’ => ‘DESC’, ‘posts_per_page’ => $my_nb, ‘auteur’ => $my_auteur, ‘category_name’ => $my_cat, ); $the_query = new WP_Query( $args ); $txt .= “<div class=’grid’>”; if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $txt .= ‘<div>’; // $my_post_id = $post->ID; $txt .= “<a href='”; $txt .= get_permalink(); $txt .= “‘>”; $txt .= get_the_post_thumbnail($the_query->post->ID); $auteur = strip_tags( get_the_term_list( $the_query->post->ID, ‘auteur’, ”, ‘, ‘, ” )); $categories = get_the_category(); $my_cat=””; if ( ! empty( $categories ) ) { $my_cat = $categories[0]->slug;} $txt .= ‘<h3 class=”‘.$my_cat.'”><span class=”cover_author”>’; $txt .= preg_replace(‘/(.*) /’,'<i>$1 </i>‘,$auteur).”</span><br>”; $title = get_the_title($the_query->ID); //$my_title = str_replace(“|”,”</span><br><span class=’cover_author’><i>”,$title); //echo preg_replace(‘/(.*) /’,’$1 </i>‘,$my_title); $txt .= “<span class=’cover_title’>”.$title; $txt .= ‘</span></h3>’; $txt .= ‘</div>’; } } wp_reset_postdata(); $txt .= “</div>”; return $txt; } add_shortcode( ‘ebooks’, ‘ebooks_func’ );
In fact, it is a simple wp query post /// with this args :
$args = array(
‘post_type’=> ‘post’,
‘order’ => ‘DESC’,
‘posts_per_page’ => $my_nb,
‘auteur’ => $my_auteur,
‘category_name’ => $my_cat,
);I don’t why, when I make a query, it shows me all posts … and don’t hide protected posts … may be I missed something …
thx Predrag
Hi @theeponymus,
I just tested your shortcode within default WP theme and there it worked fine, protected posts were not shown in the query.
So the issue is not within the shortcode code, it’s something else in your theme that’s preventing M2 from working properly.
I’m afraid that this is something best discussed with your theme developers as they are familiar with theme code and could give you more insight on this.
Cheers,
Predrag
- The topic ‘Don’t show post at all in loop …’ is closed to new replies.