Limit number of posts in loop

I consider the right way could be filtering of total number of found posts like this. function my_custom_found_posts_limiter( $found_posts, $wp_query ) { $maximum_of_post_items = 100; // place your desired value here or read if from option\setting. if ( ! is_admin() && $wp_query->is_main_query() && $wp_query->is_post_type_archive( ‘blog_posts’ ) ) { if ( $found_posts > $maximum_of_post_items ) { … Read more

How to get dropdown instance value in WordPress custom Widget

The cat_drop setting is empty because your drop-down menu, or the select field doesn’t have the proper name value, so PHP isn’t receiving the selected option/value. So to fix the issue, just add the proper name value to the select field: <!– Wrapped for brevity. –> <select name=”<?php echo $this->get_field_name( ‘cat_drop’ ); ?>” id=”<?php echo … Read more

How to get theme’s info from wordpress.org/themes using api.wordpress.org?

If you’re in the admin site you can use themes_api() $info = themes_api( ‘theme_information’, [ ‘slug’ => ‘twentyten’ ] ); echo esc_textarea( $info->sections[‘description’] ); but that’s plain text, not HTML. The API request it generates is https://api.wordpress.org/themes/info/1.2/?action=theme_information&request%5Bslug%5D=twentyten&request%5Blocale%5D=en_US&request%5Bwp_version%5D=5.3.2 You can see the parameters in there as multiple URL-encoded request[key] parameters.

Woocommerce Sort by default variation price

get_variation_default_attributes and woocommerce_price are depreciated. This works for me. If I have set default attributes. function custom_variation_price( $price, $product ) { foreach($product->get_available_variations() as $pav){ $def=true; foreach($product->get_default_attributes() as $defkey=>$defval){ if($pav[‘attributes’][‘attribute_’.$defkey]!=$defval){ $def=false; } } if($def){ $price = $pav[‘display_price’]; } } return wc_price($price); }

WooCommerce – Conditional for page created by rewrite_rule

In WordPress, the request path, e.g. path/to/something as in example.com/path/to/something?query=string&if=any, is saved in WP::$request which is accessible via the global $wp variable, so in your case, you can do so to check if the page is /dashboard/products: global $wp; // Note: No trailing slashes. $is_my_page = ( ‘dashboard/products’ === $wp->request ); // Or without the … Read more

Show icons or badges under title on product archives/category pages

So I was not able to solve my problem earlier, then I switched the plugin to “Category and Taxonomy Image” (by Aftab Hussain) and used the following code to display the icons on category/archive pages: add_action( ‘woocommerce_after_shop_loop_item’, ‘attribute_img_loop’, 20 ); function attribute_img_loop() { global $product; // Check that we got the instance of the WC_Product … Read more

Display site language setting in source code

Is it possible to display <!– plugin version 123 (Fr) –> if the language is French? Yes, it is possible and you can use get_bloginfo( ‘language’ ) which returns a language tag like en-US for English (US). So if you just want to retrieve the first 2-or-3 character code (e.g. en for en-US and en-UK) … Read more