Restrict next_post_link() to current category

OK, so there’s a problem with Codes in this part, I guess. The Codex article on Next and Previous Links contradicts the article specifically on next_post_link() In that article you can clearly see, that it looked a little bit different. In the part describing next_post_link there is a note: Deprecated: previous_post() and next_post(). Use: –> … Read more

Define a wordpress constant through plugin functions?

I don’t think you should define constants in your plugin. It will be very hard to debug later on. IMHO using wp_revisions_to_keep filter will be much nicer solution. So your code could look like this: add_filter( ‘wp_revisions_to_keep’, ‘my_revisions_to_keep_based_on_settings’, 10, 2 ); function my_revisions_to_keep_based_on_settings( $num, $post ) { // change that according to your needs return … Read more

Add ajax load more function using WP API

I’ve solved the problem, I was made a mistake with the variable pull_page that is inside the click event. I’ve moved the variable outside the event and now all works fine. Here is the updated code! var pull_page = 1; var jsonFlag = true; $(‘#load-more’).on(‘click’, function(e){ e.preventDefault(); if(jsonFlag){ pull_page++; $.getJSON(“/u/wp-json/portfolio/all-posts?page=” + pull_page, function(data){ if(data.length){ pull_page++; … Read more

Hiding Posts on Front Page and from all plugins

If you want to hide certain posts from all queries on the front page, then remove the conditions you’re using and check is_front_page() instead: function exclude_single_posts_home($query) { if (is_front_page()) { $query->set(‘post__not_in’, array(69489,69177,68878,68736)); } } Normally checking the global state is the incorrect way to filter queries (what you’d originally done is the normal correct way), … Read more

View the number of entries recorded per day

The easiest way is by using custom MySQL query with WPDB class. global $wpdb; $table = $wpdb->prefix . ‘posts’; $sql = “SELECT DATE(post_date) AS date, COUNT(ID) AS count FROM {$table} WHERE post_type=”my_post_type” AND post_status=”publish” GROUP BY DATE(post_date)”; $rows = $wpdb->get_results($sql); Or if you want to prevent SQL injection, you can use prepared statement like this: … Read more

Copying and pasting emoji in a wordpress post

Emoji are just letters. They’re defined by the user’s operating system. The same way the alphabet is. You don’t need to do anything special. If you did, then that website would be pointless. The only thing you need to consider is older operating systems that don’t support Emoji, but WordPress itself loads a script that … Read more

Ajax posts filter by date, comments, top views, top likes

I haven’t tested the code, but this should help. option elements do not have a name attribute: <option name=”top-views” value=”top-views”>Top Views</option> <option name=”top-likes” value=”top-likes”>Top Likes</option> And therefore $_POST[‘top-views’] for example, is not going to be set, or that the value is not the top-views in the above option. Use the proper option markup Based on … Read more

Can I create a not clickable post?

You can do it in many ways but I think every needs to change your archive template (or other template which display your list). You can use some custom field plugins to add one with “Don’t link do article” and set this in your template in places where you have anchors. That’s a quick solution. … Read more