Making your own custom post views count

For example, how does “Most Popular Posts” plugin calculate views. Do they simply update custom post meta_value +1 every time there’s a page refresh? Yes some do that yes, but using post meta and updating it on every visit will give you wildly inaccurate results due to race conditions, is incompatible with page caching/CDNs, and … Read more

How to deal with too many $_POST variable conditions from ajax request at backend? [closed]

I Would start with creating a array that hold all “conditions” logic, loop it, check to see if some condition is met and return the value. $conditions = [ ‘variable_1’ => ‘DoSomeStuffWithVariable_1’, ‘variable_1’ => ‘DoSomeStuffWithVariable_1’, ‘variable_1’ => ‘DoSomeStuffWithVariable_1’, ‘variable_xy’ => ‘DoSomeStuffWithVariable_xy’ ]; foreach ($conditions as $condition_key => $condition_value) { if (isset($_POST[$condition_key])) { $returnArray[‘return’] = $model->$condition_value(); … Read more

Adding conditional text to a PHP Shortcode Template

The strings use in your plugin are using translatable strings ie. _e( ‘Inbox’, WPC_CLIENT_TEXT_DOMAIN ) It would probably be a better idea to use a translation plugin such as WPML or Polylang as opposed to trying to do this conditionally within the template files. However, if you prefer to do this within the template file … Read more

Multiple requests external data api dynamic block gutenberg

You could use transients: function requestApi() { $cache_key = ‘your_transient_name’; $values = get_transient( $cache_key ); // if no data in the cache if ( $values === false ) { // build the URL for wp_remote_get() function $arguments = [ ‘method’ => ‘GET’, ]; $request = wp_remote_get( ‘https://example.com.br/api/endpoint/product-id’, $arguments ); if ( !is_wp_error( $request ) && … Read more

How to pass a variable into an add_filter() function?

You could use an anonymous function and pass the variable to it with use. $updatedLanguage = $languageArray[$pageLanguage] ?? ”; if ( $updatedLanguage ) { add_filter(‘locale’, function($locale) use ($updatedLanguage) { return $updatedLanguage; }); } If you’re changing the locale at runtime, then you may want to look here Change locale manually at runtime?, where it is … Read more