Get specific posts by ID in wordpress

Try this: <?php $thePostIdArray = array(“11”, “13”, “15”, “17”, “19”); $limit = 5; $query=new WP_Query(array(‘post__in’=>$thePostIdArray)); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); $counter++; if ( $counter < $limit + 1 ) : $post_id = $thePostIdArray[$counter-1]; $queried_post = get_post($post_id); ?> <a href=”https://wordpress.stackexchange.com/applications”> <div class=”col-md-5 apps text-center”> <?php the_post_thumbnail(‘full’, array( ‘class’ => ‘img-responsive’ … Read more

Getting current post ID in functions.php

I believe this should work in all cases – whether you are in the loop or not. (In a widget, chances are you are not in the loop) Mind you, outside the loop, this will work very well on single pages or posts, but might not display the post you want on other types of … Read more

Loop through all product posts?

Take a look at WordPress codex for WP_Query for more information. You’ll see there are different parameters for WP_Query, you just need to add the posts_per_page parameter with the value set to -1 to show all posts. $products_IDs = new WP_Query( array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, )); while ($products_IDs->have_posts() ) : $products_IDs->the_post(); // … Read more

Get Posts via Taxonomy Term Name with Space

You could get the posts by slug instead of name. Like this: $posts = get_posts(array( ‘post_type’ => ‘coupon’, ‘numberposts’ => -1, ‘post_status’ => array(‘publish’, ‘unreliable’, ‘draft’), ‘tax_query’ => array( array( ‘taxonomy’ => ‘stores’, ‘field’ => ‘slug’, ‘terms’ => array( ‘new-store’ ), ‘include_children’ => false ) ) )); Or you could get the posts by term … Read more

Encrypt / Decrypt Post Title and Details

To change post content before it gets saved you can use wp_insert_post_data filter. I’m using in this example just a simple/dummy way to represent the encryption, I’m just replacing each char with the correspondent ascii code. It should be replaced by your encryption method. add_filter( ‘wp_insert_post_data’ , ‘encrypt_post’ , 99, 1 ); function encrypt_post( $data … Read more

Is there any way to allow users to access content before it’s published?

You can use this in a template file: $tomr = getdate(time()+86400); //utc=gmt time in seconds, add 24 hours = 86400 seconds $args = array( ‘post_status’ => ‘future’, ‘date_query’ => array( array( ‘year’ => $tomr[‘year’], ‘month’ => $tomr[‘mon’], ‘day’ => $tomr[‘mday’], ‘column’ => ‘post_date_gmt’ //since we are using the gmt timestamp ), ), ); $query = … Read more

WordPress’ visual editor messing up my (nested) lists (and other things as well)

Instead of using the “type” attribute, try adding a CSS class and styling that. <ol> <li>Number one</li> <li>Number two <ol class=”lower-alpha”> <li>Lowercase a</li> <li>Lowercase b <ul> <li>Paragraph 1</li> <li>Paragraph 2</li> </ul> </li> </ol> </li> </ol> Then in your CSS – depending on your site setup, you may want to add Custom CSS through the Customizer, … Read more