Generate permalinks

The second argument of wp_unique_post_slug filter is post id. You can utilize that to generate the slug only once while creating the post for the first time. Method 1: add_filter( ‘wp_unique_post_slug’, ‘unique_slug_108286’, 10, 2 ); function unique_slug_108286( $slug, $postId ) { if ( ! $postId ) { $n = 4; $slug = bin2hex( random_bytes( $n … Read more

wp_remote_post with ssl:// protocol

This doesn’t seem to be error coming from WP itself, but is likely generated by curl, which WP likes to pick first for network requests. I’d try to replicate request with curl by hand on your hosting and elsewhere. If you are content with doing network request in other way you can tweak to make … Read more

Unable to get_the_content(); of a post in WordPress via AJAX

get_the_content() must be used inside the loop, or otherwise you’ll need to use setup_postdata(); providing the post object. Try the following: function ajax_action_stuff() { $post_id = $_POST[‘post_id’]; //Query the post and set-up data $post = get_post($post_id); setup_postdata( $post ); update_post_meta($post_id, ‘post_key’, ‘meta_value’); //Return response as an array. This will give us data.title and data.content browser-side. … Read more

How to display most viewed post in my sidebar?

As per @userabuser comment: <?php /* Plugin Name: Simple Post Views Plugin URI: http://en.bainternet.info Description: Simple And lightweight plugin to track post views. Version: 0.1 Author: Bainternet Author URI: http://en.bainternet.info */ if ( !class_exists(‘PostViews’)){ class PostViews{ static $meta_key = “_post_views_count” //class constractor public function __construct(){ //auto count view on the_content function. add_filter(‘the_content’,array($this,’setPostViews’)); //add shortcodes add_shortcode(“TOP_VIEWED”,array($this,’top_viewed’)); … Read more