Monday, February 29, 2016

wp - setup_postdata($post2) wont work

It has to be

global $post;


otherwise, you might get wrong link in the_excerpt and so on


If it redirects to the other version of the post, make sure you check .htaccess and any of the REDIRECT plugins.

Also, it can be caused by the non-unique slug!


In some configurations (probably  due to what is being translated by WPML ), if get_field("name", post_id) fails, the original content can  be obtained by:

get_field("name", $orig_lang_id);

Sunday, February 28, 2016

PDO Emulated Prepares

Here are some links regarding PHP PDO's emulated prepared statements, which seem to be an important PHP issue:

Friday, February 26, 2016

PHP server serving valid content but still returning status code 404


You have an ajax script get-data.php which should return valid JSON data.

When you use your web browser to open the page, everything looks good, and you can seee the JSON.

However, when you issue a jQuery AJAX call, it always returns error 404.

In my case, I wasn't checking carefully enough, because the page returned the status code 404, even it served the content properly. This was probably caused by WP functions included in my script.

When I used http_status_code(200) manually, all went back to work :)

Moral  of the story: Your  scripts sometimes contain extra code which can cause troubles. :O

Disable caching and preserve logs in Google Chrome Developer Console

If you cannot fetch all issued AJAX requests in your Google Chrome Dev Console, make sure you try to set these two options:
Disable Caching
Enable Preserve Logs

Both of these can be set/unset on the Network tab of Google Chrome Developer Console.

WP - ACF get_field problems with WPML

If you find your get_field('field_name', post_id) not working sometimes in your WPML site, you can try this trick:

global $sitepress;
$current_lang = $sitepress->get_current_language(); //save current language



This will temporary change the langauge of site, to enable get_field to get proper data. This could be some kind of bug in WPML/ACF combinations. Needs further checking.

Saturday, February 20, 2016

phpStorm FTP connection timeout

If you are having issues testing or using your FTP deployment feature of PHPStorm IDE, you can try setting Passive mode in Advanced Settings.

Friday, February 5, 2016

WP - media_handle_sideload duplicates images on WooCommerce import

If you are using WooCommerce import plugins, you will probably notice that your Media Folder will soon contain lots of duplicate images (or at least duplicate references ).

The reason for this is the fact that this is the default behavior for media_handle_sideload and download_url functions.

The easiest way to prevent this, is to find the code responsible for image processing in the WC Import plugin, and then first delete all the existing images attached to that product / post:

A script like this could help (in case of WooCommerce CSV Import plugin, this goes to save() function in class-woocommerce-product.php):

               $post_id = $this->body['ID'];

$old_att =  get_attached_media("image", $post_id);

foreach($old_att as $key=>$val)



Here, $post_id refers to WooCommerce's product id.
This should  called only once, for each product, prior to uploading new images.

Wednesday, February 3, 2016

WP - Importing Revolution Slider fails

In Wordpress, when you are exporting / importing Revolution Slider sliders and getting a message like "slider_export.txt  not found" or "Incompatible archive", you can try this:

-Unpack your slider's zip file and re-zip it. Just be sure to match the same folder structure as the original zip

It seems that some servers provide invalid zip archives for some reason. Needs more checking.

VS2013 - Operation could not be completed (opening a .cshtml file)

In VS2013, you suddenly cannot open a CSHTML file.
The error message goes: Operation could not be completed.

Here's what you can check:

Try to run the project
You probably have an error in web.config

PSR-1 and PSR-2 coding standards for PHP

Visual aspects of code play a significant role in raising or drowning developer's productivity. In case that there's too much clutte...