How to exclude or filter password protected posts when using next_post_link() previous_post_link

The function next_post_link() allow excludes, with the parameter excluded_terms. Add a list of the IDs of the password protected posts to this param. You get a list of all password protected posts with the follow example via DB select. $password_pages = $wpdb->get_col(“SELECT ID FROM $wpdb->posts WHERE post_status=”publish” AND post_type=”post” AND post_password !=””); Alternative can you … Read more

While loop with bootstrap [closed]

Try using the count variable to increment the loop. <div class=”panel-group” id=”accordion” role=”tablist” aria-multiselectable=”true”> <?php if(get_field(‘faq_general_ht’)): ?> <?php $count=0; ?> <?php while(has_sub_field(‘faq_general_ht’)): ?> <div class=”panel panel-default”> <div class=”panel-heading” role=”tab” id=”headingTwo”> <h4 class=”panel-title”> <?php echo ‘<a data-toggle=”collapse” data-parent=”#accordion” href=”#collapse’ .$count. ‘”aria-expanded=”true”>’ ?> <p><?php the_sub_field(‘faq_general_question_ht’) ?></p> </a> </h4> </div> <?php echo ‘<div id=”collapse’ .$count. ‘” class=”panel-collapse collapse” … Read more

How to check if a product is purchased within the last 365 days before displaying something

This is not that complicated, here is a code snippet that will get you started: if(is_user_logged_in()) { //We only need these products to check $products_to_check = array(81,82,83,84); $customer_bought = array(); //Get all orders made by the current user in the last 365 days $customer_orders = get_posts( apply_filters( ‘woocommerce_my_account_my_orders_query’, array( ‘numberposts’ => $order_count, ‘meta_key’ => ‘_customer_user’, … Read more

Echo a shortcode div after every 3 posts

First, let’s clean up this tag SPAM nightmare so we can read it and then simplify the code: function adinserter() { return ‘abcdefg’; } if (have_posts()) { $count = 0; while (have_posts()) { the_post(); $count++; get_template_part( ‘content’, get_post_format() ); if ($count == 3) { if (function_exists (‘adinserter’)) { echo adinserter (1); } $count = 0; … Read more

Make loop alphabetical

You have to alter the query and add the orderby argument specified as name. I would go for the pre_get_posts action (see documentation) with some conditional tags to select the query for the right page. For example: function change_posts_order($query) { if($query->is_home() && $query->is_main_query()) { // edit to match the desired page $query->set(‘orderby’, ‘name’); $query->set(‘order’, ‘ASC’); … Read more

add bootstrap post slider with tabs

There’s probably some better way of doing this, but thought i’d give it a go anyways 🙂 – also got some of the answer from here Adding active class to first item <div class=”container”> <div id=”myCarousel” class=”carousel slide” data-ride=”carousel”> <!– Wrapper for slides –> <div class=”carousel-inner”> <?php $c = 0; $class=””; $args = array( ‘posts_per_page’ … Read more

How to add div blocks after certain set of post

use % to set the template(style) or you can use :nth-child(16n+1) … <?php if (have_posts()) : ?> <?php $count = 0; ?> <?php $st = 16; //after how many blocks you want to repeat the pattern <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count%$st == 1) : ?> <div class=”style-1″><?php the_content(); … Read more

Custom WP_Query doesn’t display all posts

All thanks to @PieterGoosen’s comment, I figured out that this issue was due to a setting within the WPML (multilingual) plugin. Under the ‘translation management’->’multilingual content setup’ tab of the plugin settings, there is a section for ‘custom posts’. In this section, my ‘publications’ post type was not set for translation, and this somehow prevented … Read more