Setting up navigation links for posts (first, prev, next, last)

This gist should get you started. <?php /* Plugin Name: Easy Pagination Deamon Plugin URI: http://wordpress.org/extend/plugins/stats/ Description: Offers the deamon_pagination($range) template tag for a sematically correct pagination. Author: Franz Josef Kaiser Author URI: http://say-hello-code.com Version: 0.1 License: GPL v2 – http://www.gnu.org/licenses/old-licenses/gpl-2.0.html Text Domain: pagination_deamon_lang Copyright 20010-2011 by Franz Josef Kaiser This program is free software; … Read more

AJAX filter posts by year

Try by change appropriate code: Front end <form action=”<?php echo site_url()?>/wp-admin/admin-ajax.php” method=”POST” id=”filter> <select name=”year”></select> <input type=”hidden” name=”action” value=”filter” /> </form> JS ajax request $.ajax({ url : filter.attr(‘action’) , data : filter.serialize() , type : filter.attr(‘method’) , success : function (response) { console.log(response) }, error : function (request , status , error) { console.log(request.responseText) console.log(error) … Read more

How do I use `posts_distinct` correctly?

You can see a practical example here: https://wordpress.stackexchange.com/a/142902/19105 Why do you need to use DISTINCT in this situation though? The WP_Query you provided shouldn’t be giving duplicates unless there is a plugin causing trouble. But I’ll try to answer it anyway. I would suggest keeping the function in functions.php. But move the filter to archive.php … Read more

How to get a list of all the years that have posts

I am not sure why you prefer the longer method over wp_get_archives(). I recommend letting WordPress do the work for you. It is more efficient, and easier to read. However … since you presented a particular preference: It would appear that you are using an array for post_type, when none is required. Try modifying your … Read more

Invisible spam post in backend

I’d try open the spam post in your browser and find the post ID. This will be in a rel=”shortlink” tag in the HTML header: <link rel=”shortlink” href=”https://example.com/?p=123″ /> or as a class page-id-123 or similar on the body tag: <body class=”page-template-default page page-id-123 logged-in admin-bar no-customize-support”> edit that ID into your normal edit post … Read more

Remove slashes (both before and after) in relative post url

It’s because you’re not actually putting the result of ltrim() and rtrim() back into the variable. Those functions return the trimmed value, they don’t modify the passed variable. So you need to do this: $post_url_rel = wp_make_link_relative(get_permalink( $post_id )); $post_url_rel = ltrim($post_url_rel, “https://wordpress.stackexchange.com/”); $post_url_rel = rtrim($post_url_rel, “https://wordpress.stackexchange.com/”); Or better yet, just use trim(), which will … Read more