Limit popular posts by days

Here is a function which show the posts of last 7days or you can change it according to your requirement. function filter_where($where=””) { //posts in the last 7 days $where .= ” AND post_date > ‘” . date(‘Y-m-d’, strtotime(‘-7 days’)) . “‘”; return $where; } add_filter(‘posts_where’, ‘filter_where’);

get_posts() doesn’t consider user permissions

Use is_user_logged_in you code may like $posts_array = get_posts( array( ‘post_type’ => ‘download’, ‘post_status’ => ‘publish’ ) ); //$posts_array = apply_filters( ‘downloads_shortcode’, $posts_array ); foreach($posts_array as $post) { setup_postdata($post); if ( is_user_logged_in() ){ $title = “<a href=”https://wordpress.stackexchange.com/questions/100335/. get_permalink( $post->ID ) .”>” . $post->post_title . “</a>”; echo $title; } else{ // do something } } Note:If … Read more

WordPress not opening posts with only numbers if permalink is post_name

Sorry I didn’t follow up on this. You mentioned you weren’t using date archives. You can change the date archive structure to remove the conflict with /%postname%/: function wpa_change_date_structure(){ global $wp_rewrite; $wp_rewrite->date_structure=”date/%year%/%monthnum%/%day%”; } add_action( ‘init’, ‘wpa_change_date_structure’ ); So now after permalinks are flushed, date archive URLs will be prefixed with date/, so numeric postnames will … Read more

Get mixed category random posts

I whipped this up: echo ‘<ul>’; the_random_posts(); echo ‘</ul>’; /** * Send random posts to the browser (STDOUT). */ function the_random_posts() { // Use your own category ids. $random_posts = array_merge( get_random_posts( 31, 3 ), get_random_posts( 11, 1 ), get_random_posts( 24, 1 ) ); foreach ( $random_posts as $post ) { // Change this line … Read more

How do I restart my loop with get_next_post()?

get_next_post doesn’t really know what the “beginning” is. get_next_post uses get_adjacent_posts. If you look at the source, you can see that that function runs its own query to determine the next (or previous) post relative to the current post. It doesn’t loop through a list. To get the “first” post, you will need to run … Read more

Get posts from taxonomy URL

So I’m taking some liberties with this, I’m assuming a couple things: You know the taxonomy the term belongs to You have the term archive link So if I have the term archive link: $url=”http://www.example.com/taxonomy/term/”; I know that the last part of that url is going to be the terms slug. I can use the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)