How do I retrieve a users’ last 5 posts?

Basically, when you want get posts, you should think about WP_Query. It’s already in the docs for your question. You can get posts by an author like this $query = new WP_Query( array( ‘author’ => AUTHOR_ID, ‘posts_per_page’ => 5 ) ); You can even get posts by more than one author, like this $query = … Read more

How to get a post’s content? [closed]

“best” greatly depends on context. guid is probably (with some debate about it) the best way to uniquely identify a post, but not all import/export plugins leave it alone without changes. ID is a good identifier if you do not care about import and export. Slug is problematic because they might be changed by the … Read more

How to get posts from a current post’s month?

There is date_query which can handle this and an SQL query is not a good practice when you can take advantage of WordPress Query API: $pid = 1; // post ID here $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ‘date_query’ => array( array( ‘year’ => get_the_date(‘Y’, $pid), ‘month’ => get_the_date(‘m’, $pid) ), ), … Read more

how to get random post id by using post type

As far I understood you want to set the value of $id randomly from adzones post type post ids. I hope this helps you- $args = array( ‘orderby’ => ‘rand’, ‘posts_per_page’ => ‘1’, ‘post_type’ => ‘adzones’ ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $id = get_the_ID(); echo do_shortcode(“[pro_ad_display_adzone id=”.$id.”]”); … Read more

Possible to alternate between two loops

You need two queries for this. Let’s say the ID of the featured category is 5. Then you set up two queries retrieving 3 posts each: $query1 = new WP_Query( array( ‘cat’ => ‘5’, ‘posts_per_page’ => 3 ) ); $query2 = new WP_Query( array( ‘cat’ => ‘-5’, ‘posts_per_page’ => 3 ) ); Now you have … Read more

Shortcodes on my website stops working after theme update [closed]

most likely your [download_ebook_lead_form ret_url=””] shortcode was defined in functions.php in your theme parent folder, and during update the file was somehow replaced with new one. If you have backup of previous version of your theme check its functions.php and look for add_shortcode( ‘download_ebook_lead_form’…). If you find it there just copy entire function to functions.php … Read more

Only show a Post once in 10 visits

function lsmwp_post_limter($ids, $in, $count) { $i = rand(1,$count); if ($i <= $in) { return($ids); } else return false; } function lsmWpfilter($posts){ $result = []; foreach($posts as $post){ $res = lsmwp_post_limter($post[‘postId’], $post[‘in’], $post[‘count’]); if ($res){ $result[] = $res; } } print_r($result); return $result; } $exluded_posts = array( array(‘postId’ => 28741 , ‘in’ => 2, ‘count’ => … Read more

How to include my own css in post

The easiest way in most recent themes is to use the Custom CSS from the Theme Customizer. If it is enabled in your theme, you can access it through: Appearance -> Customize. If it’s not enabled, you should first refer to your theme’s documentation. Is it a free or bought theme?