Support » Themes and Templates » Customized wp_get_archives Link

  • Hi everybody,

    I’m getting my yearly based custom-post-type archive like this:

    $args = array ( 
    'type' => 'yearly',
    'post_type'    => 'project',
    'format' => 'custom',
    'before' => '<li value="2016" data-filter-value=".classof2016">',
    'after' => '</li>'
    );
    wp_get_archives($args);				
    ?>

    I altered the function in function.php, so that I can parse my custom post types like this:

    function my_custom_post_type_archive_where($where,$args){  
        $post_type  = isset($args['post_type'])  ? $args['post_type']  : 'post';  
        $where = "WHERE post_type = '$post_type' AND post_status = 'publish'";
        return $where;  
    }
    
    add_filter( 'getarchives_where','my_custom_post_type_archive_where',10,2);

    As you can see, I’m creating a value that should be related to the year. How can I add this term in the html?

    Thanks for your help!

    • This topic was modified 2 years, 9 months ago by  cgoldt.
    • This topic was modified 2 years, 9 months ago by  cgoldt.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, could somebody help here? Thanks in advance! Cara

    • This reply was modified 2 years, 9 months ago by  cgoldt.

    I solved it like this:

    add_filter( 'get_archives_link', function( $link_html, $url, $text, $format, $before, $after ) {
    
        if ( 'custom' == $format ) {
            $link_html = "\t<li value=\"". esc_attr( $text ) ."\" data-filter-value=\".classof". esc_attr( $text ) ."\">$before<a href='$url'>$text</a>$after</li>\n";
        }
    
        return $output;
    
    }, 10, 6 );

    Thanks to this answer on stackoverflow.

    • This reply was modified 2 years, 9 months ago by  cgoldt.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Customized wp_get_archives Link’ is closed to new replies.