{"id":447,"date":"2016-07-19T11:33:45","date_gmt":"2016-07-19T11:33:45","guid":{"rendered":"http:\/\/pixert.com\/blog\/?p=447"},"modified":"2023-03-20T01:30:05","modified_gmt":"2023-03-20T01:30:05","slug":"wordpress-randomize-posts-category-page","status":"publish","type":"post","link":"https:\/\/pixert.com\/blog\/wordpress-randomize-posts-category-page\/","title":{"rendered":"WordPress: Randomize posts in a category page"},"content":{"rendered":"<p>The following lines of code change the way of displaying posts in a category page from default to date to random order. Please add following lines of code to functions.php<\/p>\n<pre><pre class=\"brush: php; title: Code Block; notranslate\" title=\"Code Block\">\n\nadd_action( 'pre_get_posts', 'random_category_posts' );\nfunction random_category_posts( $query ) {\nif ( $query-&amp;gt;is_category() &amp;amp;&amp;amp; $query-&amp;gt;is_main_query() ) {\n$query-&amp;gt;set( 'orderby', 'rand' );\n}\n}\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following lines of code change the way of displaying posts in a category page from default to date to random order. Please add following lines of code to functions.php add_action( &#8216;pre_get_posts&#8217;, &#8216;random_category_posts&#8217; ); function random_category_posts( $query ) { if ( $query-&amp;gt;is_category() &amp;amp;&amp;amp; $query-&amp;gt;is_main_query() ) { $query-&amp;gt;set( &#8216;orderby&#8217;, &#8216;rand&#8217; ); } }<\/p>\n","protected":false},"author":1,"featured_media":25,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[54,5],"tags":[55,6],"class_list":["post-447","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-snippet","category-wordpress","tag-code-snippet-2","tag-wordpress-2"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=498%2C113&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1pvi1-7d","jetpack-related-posts":[{"id":268,"url":"https:\/\/pixert.com\/blog\/wordpress-limit-post\/","url_meta":{"origin":447,"position":0},"title":"WordPress Limit Post","author":"Pixel Insert \/ Pixert","date":"November 30, 2012","format":false,"excerpt":"This function controls the maximum\u00a0amount of characters displayed for an entry on the main page. If the set limit is surpassed, the text on the entry will be chopped\u00a0to that amount of characters, otherwise the content will be showed unchanged. Add following code to functions.php in your theme folder [php]\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":130,"url":"https:\/\/pixert.com\/blog\/enable-formatting-tags-for-content-limit-in-genesis-featured-posts-widget\/","url_meta":{"origin":447,"position":1},"title":"Enable Formatting Tags for Content Limit in Genesis Featured Posts widget","author":"Pixel Insert \/ Pixert","date":"January 10, 2013","format":false,"excerpt":"Genesis Framework has same function that return the content after trimming and it strips all HTML The following code help you keep or filter some HTML tags when you are using Content Limit in Theme Settings or Widgets (e.g Genesis - Featured Posts widget) Add following to functions.php in the\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/01\/gallerygenesis.jpg?fit=600%2C340&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/01\/gallerygenesis.jpg?fit=600%2C340&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/01\/gallerygenesis.jpg?fit=600%2C340&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":201,"url":"https:\/\/pixert.com\/blog\/remove-wordpress-revisions\/","url_meta":{"origin":447,"position":2},"title":"Remove WordPress Revisions","author":"Pixel Insert \/ Pixert","date":"February 16, 2012","format":false,"excerpt":"WordPress Posts Revisions are useful especially in the case of a multi author blog. However, There is a cost to having all these saved revisions of your posts in the aspect of database entries. Instead of having a single MySQL database record for your post you will have multiple records\u2026","rel":"","context":"In &quot;WordPress&quot;","block_context":{"text":"WordPress","link":"https:\/\/pixert.com\/blog\/category\/wordpress\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":305,"url":"https:\/\/pixert.com\/blog\/wordpress-conditional-tag-to-check-specific-menu\/","url_meta":{"origin":447,"position":3},"title":"WordPress: Conditional tag to check a specific menu","author":"Pixel Insert \/ Pixert","date":"May 22, 2013","format":false,"excerpt":"Following conditional tag usually use in this filter function, wp_nav_menu_items [php]if( $args->theme_location == 'primary' )[\/php] \u00a0 [php]if( $args->theme_location == 'secondary' )[\/php] \u00a0 [php]if( $args->theme_location == 'primary' )[\/php] For an example, I want to add search box to Primary Menu in WPZOOM theme name Videozoom. Conditional tag above make sure the\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"wordpress-logo-notext-rgb","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/08\/wordpress-logo-notext-rgb.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":416,"url":"https:\/\/pixert.com\/blog\/wordpress-title-empty-on-index-page\/","url_meta":{"origin":447,"position":4},"title":"WordPress Title Empty on Index Page","author":"Pixel Insert \/ Pixert","date":"November 2, 2014","format":false,"excerpt":"Here's description from WordPress Codex about what happen when WordPress title empty when viewing index page\/ homepage If you are using a custom homepage with custom loops and stuff or a custom front-page, you will have an empty wp_title. I recently encountered this problem on a client's site. Homepage\/Index page\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":393,"url":"https:\/\/pixert.com\/blog\/add-facebook-like-box-change-language-local\/","url_meta":{"origin":447,"position":5},"title":"How to add Facebook Like Box and change language to local","author":"Pixel Insert \/ Pixert","date":"September 21, 2014","format":false,"excerpt":"Facebook Like Box\u00a0allows website owners to provide their visitors with an easy way to join their facebook community and get updates right in their Facebook news feed with a click to like from\u00a0their website. It\u00a0is\u00a0a good\u00a0way\u00a0to promote a \u00a0Facebook Page. Facebook Like Box only works for Facebook Pages, this isn't\u2026","rel":"","context":"In &quot;WordPress&quot;","block_context":{"text":"WordPress","link":"https:\/\/pixert.com\/blog\/category\/wordpress\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2014\/09\/facebooklikebox.jpg?fit=447%2C547&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts\/447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/comments?post=447"}],"version-history":[{"count":2,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts\/447\/revisions"}],"predecessor-version":[{"id":632,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts\/447\/revisions\/632"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/media\/25"}],"wp:attachment":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/media?parent=447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/categories?post=447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/tags?post=447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}