Images Uploaded saving onto older/previous year folders

You should check yourself what you get when you execute wp_upload_dir. Typically you run this code: $d = wp_upload_dir(); print_r( $d ); wp_die(); And the reply needs to be like this in 2017/01 Array ( [path] => /var/www/html/test100.com/wp-content/uploads/2017/01 [url] => http://test100.com/wp-content/uploads/2017/01 [subdir] => /2017/01 [basedir] => /var/www/html/test100.com/wp-content/uploads [baseurl] => http://test100.com/wp-content/uploads [error] => ) You will … Read more

Infinite Loop – WP_Query

Your second loop, the $ticketQuery loop is missing $ticketQuery->the_post(). The function the_post() actually sets up things like template tags, the $post object. The most important thing it does is increments the post counter so that eventually $ticketQuery->have_posts() will eventually return false. Without the_post() is your infinite loop.

Split shortcodes to array of shortcodes

WordPress already has built in support for Nested Shortcodesprovided their handler functions support it by recursively calling. So if you have for example: [tag-a] [tag-b] [tag-c] [/tag-b] [/tag-a] As long as you recursively call do_shortcode in your shortcode function, all the shortcodes would be parsed. So you would define the functions for your shortcodes as … Read more

WordPress Random post (last 3 days posts)

You can use this code for show last 3 days post. Best of luck… $args = array( ‘post_status’ => ‘publish’, ‘type’ => ‘news’, ‘posts_per_page’ => 2, ‘order’ => ‘rand’, ‘date_query’ => array( array( ‘after’ => ‘3 days ago’ ) ) );

How to set cookies

You use setcookie() like any other function, with parameters as described in the Codex. How you would use it in a form would usually depend on how and when the $_COOKIE variable needs to be made accessible. One common method, if you want a change in the DOM both to register immediately and to persist, … Read more

speed up pagination for huge database

The article on wordpress is interesting and true but I’m not sure what’s it’s purpose. The provided code is for cases when you want to do some action for every post ; it doesn’t help with the pagination on site directly. You may try https://wpartisan.me/tutorials/wordpress-database-queries-speed-sql_calc_found_rows instead, but with million posts, even better would be to … Read more

PHP: injecting HTML into an if/else tag?

Well-written as opposed to working but poorly written code is a distinct matter of opinion and taste. There are various style guides if you’re interested in seeing examples. Personally in your example above, I would change two things: indentation, and curly braces. I find php open/closing tags in and html tags in templates to be … Read more