Adding pagination to a custom archive template

Since 4.1.0, WordPress introduce the_posts_pagination to handle number paginate link. I use it all the time, and it just works. With any custom post type. You’ll want to use that function after the while loop. See: https://developer.wordpress.org/reference/functions/the_posts_pagination/

Archive in sidebar with dropdown list of Year – Month – Day

Year, Month and Day are all public query variables, all you need to do is create a search form with appropriately named inputs. <form method=”get” action=”<?php echo home_url( “https://wordpress.stackexchange.com/” ); ?>”> <select name=”day”> <?php foreach( range(1,31) as $day_of_month ) : ?> <option><?php echo $day_of_month; ?></option> <?php endforeach; ?> </select> <select name=”monthnum”> <?php foreach( range(1,12) as … Read more

How to limit wp_get_archives to show months for the X years only

If using “regular” query in theme file (sidebar.php for example), this code will help do the trick: <?php wp_get_archives(‘type=monthly&limit=12’); ?> The above (and below) will only show the last 12 months. However if using a widget, then add this code to your functions.php file: function my_limit_archives( $args ) { $args[‘limit’] = 12; return $args; } … Read more

Get IDs of posts currently visible on archive

When the wp_enqueue_scripts action fires, the main query has already run and the posts are in the global $wp_query. We just need to grab the ID from each object in $wp_query->posts, the wp_list_pluck function makes that easy: function wpd_get_post_ids(){ if( is_archive() ){ global $wp_query; $post_ids = wp_list_pluck( $wp_query->posts, ‘ID’ ); // $post_ids now contains an … Read more

I want exclude the particular category in sidebar

Notice that you don’t need echo to display the result, since echo=1 is the default settings of wp_get_archives(). As @PieterGoosen explained, the wp_get_archives() function doesn’t support the exclude parameter. But we can use _exclude_terms, the custom parameter of the wp_get_archives() function, to exclude posts with some given terms. Here’s an example: /** * Exclude terms … Read more

How do I display the “Archives” widget layout (sidebar) in WordPress by ‘year’ then by ‘months’?

Changing the default widget would be pretty complicated. However, you can write your own shortcode and function to get your desired list. I’m guessing you want an unordered list in your widget? Put this in your theme’s functions.php: add_shortcode(‘archive_by_year_and_month’,’get_archive_by_year_and_month’); function get_archive_by_year_and_month($atts=array()){ global $wpdb; $years = $wpdb->get_col(“SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_type=”post” AND post_status=”publish” ORDER … Read more

Modify query in pre_get_posts action is messing up my nav menu

pre_get_posts runs for every query. That includes the main query, secondary queries, and menus. The problem is that is_post_type_archive(array(‘provider’)) is checking if the main query is the post type archive, not a specific query going through pre_get_posts. So when you check for that and then modify the current query going through pre_get_posts you’re going to … Read more

if in_category on archive.php

If memory serves, in_category() is for use within the loop and returns true when the current post is in that particular category. You’re probably for is_category(166).

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