Similar Posts
.So what ?
ByeminoAs you know, 3-4 letter domains are hard to come by these days, even with not so popular .tlds. “So”, I had a 3 letter a .so domain to use mainly as an url shortener. FYI: .so is the tld for Somalia, the source of inspiration for the dankest memes of the internetz. Apart from…
WP nav menu disappears on category page
ByeminoMy navigation menu started disappearing on category pages. First I suspected there was something with the header or menu location, I have double, triple checked everything and I was pulling my hair out trying to find a solution. Turns out, my attempt to order posts by a custom field interfered with the menu. if( ! $query->is_main_query())…
Fastest way to get a random post link in wp
ByeminoPreviously we have established that the fastest way to get an ID is using wpdb . So, simply to get a random post link use: function eo_get_a_rand_postlink() { global $wpdb; $rand_post_id = $wpdb->get_var(“SELECT ID FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_type = ‘post’ ORDER BY RAND() LIMIT 1”); return get_permalink($rand_post_id); }
Fastest way to get user ID in wordpress
ByeminoThere are various ways to get user_ID in WP. But which one is the fastest ? I’ve compared 3 ways function get_uid_from_global() { global $current_user; return $current_user->ID; } function get_uid_by_gcuid() { return get_current_user_id(); } function get_uid_by_wpgcu_id() { return wp_get_current_user()->ID; } Without a doubt, global method was fastest. With multiple 100,000 runs, global method took 0.9~…
How to get random tags in wordpress
ByeminoI needed a placeholder for tags input but it’s boring to display the same tags every time. But unlike posts, WP doesnt have “rand” orderby paramater. So what you can do; is to get a #no of tags and shuffle them. So basically what we do is: Check if we have a recent transient If…
Optimizing WordPress query for autocomplete search
ByeminoI was working on an autocomplete solution and I was thinking of ways to speed up the search. I will be providing a few examples with results below. Q1 is the default wordpress search with no parameters. Q2 removes the caches since they wont be really necessary. And Q3 is tailored for precision; ie: my…