On the post page I want to get all the years in which the records are posted. I use now the wp_get_archives() function. But this function gives what is needed not as it should. I do this: wp_get_archives(array('type' => 'yearly', 'post_type' => 'events')); and I get years in the markup inside the <li> and <a> tags, and I need them as a string or an array to make custom markup. Advise how this can be done!?

    1 answer 1

    You can take the wp_get_archives function as a wp_get_archives throwing out all unnecessary from it (everything is more or less clear).

    Or directly pull the data from MySQL, but this is not the most accurate option.

     SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM wp_posts WHERE post_type = 'events' AND post_status = 'publish' GROUP BY YEAR(post_date) ORDER BY post_date;