wp_get_archives() not working for my custom post type

I have my custom post type working, but I can't seem to get the archives working. Here is my code for getting the archives: <ul> <?php $args = array( 'type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC', 'post_type' => 'my_custom_post_type' ); wp_get_archives( $args ); ?> </ul> Here are the args for my CPT: $args = array( 'label' => __( 'My Custom Post Type', 'realtextdomain' …
Category: Web

Active class with custom wp_get_archives HTML output

I use a filter on get_archives_link for the HTML output and I try to reproduce the default aria-current="page" attribute on the <a> tag when we are on the archive page. if ( ! function_exists( 'o2_archives_html' ) ) : function o2_archives_html( $link_html, $url, $text, $format, $before, $after ) { if ( 'html' === $format ) $link_html = "\t<li>$before<a href='$url'><span class='label'><span class='title'>$text</span></span></a>$after</li>\n"; return $link_html; } endif; // o2_archives_html() add_filter( 'get_archives_link', 'o2_archives_html', 10, 6 ); I would like to put an "active" class …
Category: Web

Show the post date using the wp_get_archives() function?

I have some doubt about the wp_get_archives() function In my website I have create the following page template that use the wp_get_archives() function to show the posts list: <?php /** * Template Name: Posts Archive * * A custom page template for displaying all posts. * * The "Template Name:" bit above allows this to be selectable * from a dropdown menu on the edit page screen. * * @package WordPress * @subpackage Twenty_Ten * @since Twenty Ten 1.0 */ …
Category: Web

Create a CUstom Archive by Year, but just for a Single Category

I have a request from my designer to create a list of links to a page that only shows posts published by year and that belong to a specific category. So here is the design: I've found a function that can force my Archive to be just by year /** * Load Archive Widget by Year */ function my_limit_archives( $args ) { $args['type'] = 'yearly'; return $args; } add_filter( 'widget_archives_args', 'my_limit_archives' ); add_filter( 'widget_archives_dropdown_args', 'my_limit_archives' ); This is fine, as …
Category: Web

Get an array of the number of post per year of a custom post type (Wordpress)

I have a custom post type called "papers", and, to feed a chart, I need an array of the number of posts per year that have posts. I've tried with wp_count_posts() but it just give me the total number of post types, and get_archives() is just to static, and I need to use specific information like the number of post per year. Does anyone know how to do this? Hope you can help me.
Category: Web

Display only posts from referred category on date archive page

I am using wp_get_archive() in category.php. If I am on page of category=2 it should show my archives of only that category. However it is for all the categories. Following is the code for my category.php as well as archive.php <?php get_header(); ?> <?php $args =array( 'posts_per_page' =>1, ); $loop = new WP_Query( $args ); if($loop->have_posts()):while ( $loop->have_posts() ): $loop->the_post(); the_content(); endwhile; endif; ?> <?php wp_get_archives( array( 'type' => 'daily') ); ?> First part that is to show archive of …
Category: Web

Archive Meta on Product Post Type

I am using a filtered search to provide end user the ability to browse either live/published Woocommerce product listings or archived product listings; however, I am running into an issue where I am unable to expose a metakey for 'is_archived_()'. This is resulting in the user search pulling a mix of published and archived and is confusing from an ecomm standpoint. How I would like to approach this is: on the product post template, IF product post IS archived, apply …
Category: Web

wp_get_archives() - Get CSS selector for current month

I'm looking for how to get a class in the wp_get_archives functions to get the current month (when we are in a month archive) just like when we call wp_list_categories, the current category has a ".current-cat" selector for CSS or when we call wp_list_pages we have a '.current_page_item' selector.
Category: Web

How to get post archives urls list without any markup?

I'm using wp_get_archives but I cannot prepend any text inside the links. I want code like this: <a href="archive link">[my custom prepend] 2020<a/> But the 'before' option will prepend the passed string before the <a> tag. Current code is the following: $archives = wp_get_archives(array( 'type' => 'yearly' ,'echo' => false ,'format' => 'custom' ,'before' => 'News' )); So I really would like to get a list of only years and urls, without any markup, so I can build it by …
Category: Web

Yearly Archive from a custom date metabox (Event Start Date)

I have created a custom post_type called (event) and here's the code // Register Custom Post Type Events function custom_post_type_events() { $labels = array( 'name' => _x( 'Events', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Event', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'Events', 'text_domain' ), 'parent_item_colon' => __( '', 'text_domain' ), 'all_items' => __( 'All Events', 'text_domain' ), 'view_item' => __( 'View Event', 'text_domain' ), 'add_new_item' => __( 'Add New Event', 'text_domain' ), 'add_new' => …
Category: Web

How to list articles by year based on url?

Hie all, I am trying to list posts by year based on the provided url (for example: wordpressite.com/2004 - this should list all articles created in 2004), unfortunately all suggested methods from previous solutions solve the problem if the year to be queried is given. I tried creating the year.php file suggested in the wordpress hierarchy as well as date.php, but the_loop() just gives everything, not listing articles from the specific year. <?php query_posts('posts_per_page=10'); if ( have_posts() ) : while …
Category: Web

wp_get_archives doesn't take effect from css or html

I'll try to keep it short. So basically I'm trying to add custom item to my menu which in this case is the archive dropdown list with months desc. Everything looks nice and clean but the output of .wp_get_archives which also ignores all of the css function add_archive_dropdown($items, $args) { if( $args->theme_location == 'primary' ){ $items .='<li class="nav-item dropdown">' .'<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' .'Archive' .'</a>' .'<ul class="dropdown-menu" style="list-style:none;" aria-labelledby="navbarDropdown">' .'<li>' .'<a href="#">'.'August 2018' .'</a>' .'</li>' …
Category: Web

What do I need to style for the page after wp_get_archives?

http://summitcoach.web.dmitcapstone.ca/ Just a development server for now, but on the blog page I have links for monthly archives but they go to some page I believe is date.php and I just want the posts to display as they do on the blog page, but only for that month. For some reason I can't find a single thing online about this. Thanks.
Category: Web

How to create a completely functioning separate archive for posts from only 1 or 2 specific categories

I can't seem to find a complete way of resolving my issue. I've found parts, but it seems I'm the only one out there who has the issue I do. I have a web working with WP, and recently I've been asked to include a blog within the web. For the authors' ease, I decided to go about doing that by creating a specific category for the blog, so all they have to do to publish in the blog is …
Category: Web

Replace Archive Widget Link Text

I'm trying to replace the Roman numbers in the Archive Widget link (and all other numbers) with Khmer (Cambodian) numbers. But while I do replace the link text with this code, it also replaces the link url which then breaks the link. How do I just replace the archive link text, and not the url? function convert_numbers_to_khmer( $string ) { $khmer_numbers = array('០', '១', '២', '៣', '៤', '៥', '៦', '៧', '៨', '៩', '.'); $english_numbers = array('0', '1', '2', '3', '4', …
Category: Web

Date archives for custom post type

I have seen many questions/posts regarding this, but have yet to find a decent solution. Basically I am trying to do what wp_get_archives does, but for a custom post type (personally I am unsure why wp_get_archives doesn't support custom post types!). The code I am currently using is as follows functions.php function Cpt_getarchives_where_filter( $where , $r ) { $post_type = 'events'; return str_replace( "post_type = 'post'" , "post_type = '$post_type'" , $where ); } sidebar-events.php add_filter( 'getarchives_where' , 'Cpt_getarchives_where_filter' , …
Category: Web

Custom link text wp_get_archive link

Im trying to create custom text for the archive links in my sidebar. Right now it prints it but it comes out as regular text - i'm trying to make the full text output into the link. so "+ Trip {archive-link}" should be the link text <?php wp_get_archives( array( 'type' => 'yearly', 'before' => '<li class="CAPS source-bold"><span class="plus">+</span> Trip ','after' => '</li>', 'format' => 'custom', ) ); ?> any help would be greatly appreciated!
Category: Web

wp_get_archives: Put span inside anchor tags

I know how it is possible to wrap HTML around anchor elements with the inbuilt arguments for wp_get_archives. Is there a way to alter the content of the anchors in order to add a wrapping span for the anchor text? The intention is to use it for a list of yearly archives on a category (i.e. an automated list of years for which posts exist). Before: <ul> <li><a href="xx">2014</a></li> <li><a href="xx">2015</a></li> <li><a href="xx">2016</a></li> </ul> After: <ul> <li><a href="xx"><span>2014</span></a></li> <li><a href="xx"><span>2015</span></a></li> …
Category: Web

How to replace a javascript select box onchange event to a form submit action?

I have a small problem that probably has a very simple fix. I have been using the wp_get_archives() function to produce a dropdown select form. See the full code below: <form id="side-arch"> <select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> <option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option> <?php wp_get_archives( array( 'type' => 'monthly', 'format' => 'option', 'show_post_count' => 1 ) ); ?> </select> <input type="submit" value="Go" id="submit" /> </form> I would like to make this use the submit button, instead of the …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.