get_terms orderby numeric

You can use usort to sort the object $children. The function to sort after you got the $children object can be like this: usort( $children, function($a, $b) { $ai = filter_var($a->name, FILTER_SANITIZE_NUMBER_INT); $bi = filter_var($b->name, FILTER_SANITIZE_NUMBER_INT); if ($ai == $bi) { return 0; } return ($ai < $bi) ? -1 : 1; });

Limiting woocommerce line_total decimal length

Just round the decimal to two digit as per your requirement. $myID = 2859; $myorder = new WC_Order($myID); foreach ($myorder->get_items(‘line_item’) as $item) { $rounded_total = round($item[“line_total”],2);// allow 2 decimal and avoid further $Data = $Data.OrderLine($item[“name”], $rounded_total, $item[“line_tax”], $item[“qty”], “piece”, “x”); }

Set post title based on first h2 element in the content section

If you can handle this in the PHP side, you might be able to pull the h2 tags from the content using regular expression. PHP VERSION Test content $content = “<h2>This is H2 Content</h2><p>This is p content</p>Random Content<h2>This is another H2 section</h2><b><h2>This the third H2 section</h2></b>”; Grab any text inside H2s preg_match_all(‘#<h2>(.*?)</h2>#’, $content, $matches); // … Read more

PHP code inside shortcodes

You can not put PHP functions inside your shortcode. However, you do not need to. You can just use your foreach-loop to create the html and store it in a variable, for example $shortcodehtml. So, afterwards, you can call echo do_shortcode(‘[O_U user_name=”operator” blocked_message=”This page is restricted for guests.”]’ . $shortcodehtml . ‘[/O_U]’); The better version … Read more

Custom Plugin For Converting CSV To MySQL

To start with, you need to fix the define of CSV_PATH: define(‘CSV_PATH’,dirname(__FILE__)); as without that, $handle will be false – no file opened or data read. …then before you run it take another look becaue $col4 and $col5 are not set anywhere either…

Show post in slider

I used this to show images on slider .Try this <div class=”col-md-12″> <div class=”carousel carousel-showmanymoveone slide” id=”carousel123″> <div class=”carousel-inner”> <div class=”item active”> <div class=”col-xs-12 col-sm-6 col-md-3″> <img src=”https://wordpress.stackexchange.com/questions/217614/<?php echo plugin_dir_url( __FILE__ ) .”img/download-1.jpg’; ?>”></div> </div> <div class=”item”> <div class=”col-xs-12 col-sm-6 col-md-3″> <img src=”https://wordpress.stackexchange.com/questions/217614/<?php echo plugin_dir_url( __FILE__ ) .”img/download-1.jpg’; ?>”></div> </div> <div class=”item”> <div class=”col-xs-12 col-sm-6 … Read more

How to add custom post meta to default blog post?

You can use the action hook save_post_{post_type}, so for the post type ‘post’ (blog posts) it is: save_post_post. For more info see the codex. add_action( ‘save_post_post’, ‘sw150216_save_reading_time’, 10, 3); function sw150216_save_reading_time( $post_id, $post, $update ) { $reading_time = estimated_reading_time( $post ); if ( $update ) { update_post_meta ( $post_id, ‘reading_time’, $reading_time ); } else { … Read more