How to make related post order by random?

Either doesn’t seem particularly related. I would look at plugins implementing this more thoroughly if you want meaningfully related results. But to answer your question literally you can randomize order by ‘orderby’ => ‘rand’ query argument, see Order & Orderby Parameters in Codex.

Hide thumbnail if there is a gallery on the post

Just use the public API functions: has_shortcode( $content, $tag );. It uses shortcode_exists( $shortcode ); internally to search the global $shortcode_tags array for the shortcode you are searching for. If that is successful, it uses get_shortcode_regex() to search for the actual shortcode – this will save you quite some time and avoid mistakes. the_title(); if … Read more

Get images from the post

The Image added by Add Media is included in the Content.So I have splitted the image from the content.Below is the working code for my Question. <?php $output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches); ?> <div class =”single-post-flex-slider”> <ul class=”slides”> <?php for($i =0;$i<$output;$i++){ ?> <li> <img src=”https://wordpress.stackexchange.com/questions/174038/<?php echo $matches[1][$i]; ?>” width=”500px” height=”300px” /></li> <?php } ?> </ul> … Read more

Get current post’s nav menu name (term name)

You are missing a link. The posts are not assigned to the menus directly. There is a post type nav_menu_item in nav_menu taxonomy which links posts (or other kinds of destinations) to their place in menu. This snippet should get you started on retrieval: $menu_items = get_posts( [ ‘post_type’ => ‘nav_menu_item’, ‘meta_query’ => [ [ … Read more

Adding post date will not insert new post

Your code is correct. I have tested it and it works. I think what you are missing, and what I have missed while testing (banged my head against the wall for this mistake) is the fact that these posts do not show up at the top of your post list. Remember, by default, that posts … Read more

How can I set a maximum allowed post size and number of posts submitted?

The best way I know of would be to filter the data. For posts, you might do: function my_check_post_not_crazy( $data, $post_arr ) { $max_content_length = 2048; # max length in characters $max_num_posts = 200; # maximum number of posts if ( !current_user_can(‘activate_plugins’) && empty( $post_arr[‘ID’] ) ) { $die_args = array(‘back_link’ => true); # Not … Read more

Single post full screen template not inheriting WordPress role permission

The following bypasses wordpress by not going through index.php: http://prompter.rareapps.org/prompter.php?p=2193 I’d recommend that instead of doing that, you place prompter.php in your theme directory and then hijack the page to display when someone clicks the link to view full screen using the template_redirect filter: function my_special_display_view( $template ) { if ( is_page() && isset($_REQUEST[‘special_view’]) ) … Read more