custom post types, wp_get_archives and add_rewrite_rule

Custom post types do not have date-based archives by default (by which I really mean they don’t have permalink structures for their date archives). For example: www.example.com?post_type=journal&year=2012&monthnum=4 should give you the archive of journals published in April 2012. However, www.example.com/journal/2012/04 will probably give you 404 because it doesn’t exist as a re-write rule. You need … Read more

wp_get_archives for a specific category?

I did this in a relatively complicated way using a custom query. I did not know about Smart Archives Reloaded so I wrote code myself. But it works. Replace your category ID for “term_taxonomy.term_id” <?php global $wpdb, $wp_locale; $query = “select YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts from $wpdb->posts, $wpdb->term_taxonomy, $wpdb->term_relationships WHERE … Read more

Date archives for custom post type

What you want can be done also filtering ‘month_link’ for monthly archives, ‘year_link’ for yearly archives and ‘day_link’ for daily archives. You can also write a function that extends wp_get_archives to work with CPTs, adding filters to ‘getarchives_where’ and to the archive link. function wp_get_cpt_archives( $cpt=”post”, $args = array() ) { // if cpt is … Read more

wp_get_archives() – Get CSS selector for current month

Put the following function in your functions.php function wpse_62509_current_month_selector( $link_html ) { $current_month = date(“F Y”); if ( preg_match(“https://wordpress.stackexchange.com/”.$current_month.’/i’, $link_html ) ) $link_html = preg_replace(‘/<li>/i’, ‘<li class=”current-month”>’, $link_html ); return $link_html; } And then add the following line just before calling wp_get_archives() add_filter( ‘get_archives_link’, ‘wpse_62509_current_month_selector’ ); You might also want to remove the filter after … Read more

Overriding wp_get_archives() apply_filters()

A WordPress filter is a function that takes in a string, array, or object, does something to it, and returns that filtered string, array, or object. So what you want to do is turn “WHERE post_type=”post” AND post_status=”publish”” into “WHERE post_type=”post” OR post_type=”events” AND post_status=”publish””. That is fairly straightforward. From the looks of things, the … Read more

wp_get_archives: Put span inside anchor tags

Span outside anchor tags I think you’re looking for the before and after arguments (PHP 5.4+): wp_get_archives( [ ‘before’ => ‘<span>’, ‘after’ => ‘</span>’ ] ); if you want to wrap the <span> tag around the <a> tag: <li><span><a href=”https://wordpress.stackexchange.com/questions/248311/xx”>Link text</a></span></li> Span inside anchor tags If you want it inside the anchor tags: <li><a href=”https://wordpress.stackexchange.com/questions/248311/xx”><span>Link … Read more

techhipbettruvabetnorabahisbahis forumuedueduedueduedueduedueduseduedu