PHP Cookie, Raw Cookie and How to Cookie with Caching System

For years I thought I understood “cookie” very well. Especially when I figured out it’s a great way to share data between JavaScript and PHP. I always got results as I expected in many projects with this approach.

“Why not just saving the values to database and just use PHP to access it?” you might be asking. Most of the cases are because we need to access such values in JavaScript. For example, we have an eCommerce website and we let the user chooses her location with a lightbox window. The lightbox should only appear once and after the user makes the choice, it just goes away. Read More…

Data Got Wiped Out When Using Gravity Forms: Post Updates Plugin

When working with Gravity Forms, to get your post data updated at the front end, it can’t happen without this great plugin: Gravity Forms: Post Updates.

While it’s really awesome (and free) but like every (free) plugin in the wild, there is always one or two (…or three) things just can’t work as we expected.

The problem I met is, when updating the post, the post tags and some custom fields kept got wiped out. Because the post tags field was not added to the form and I hide those custom fields conditionally, I thought they got wiped out just for they didn’t exist in the form.

But soon I found the custom fields were in the form but got hidden with inline CSS “display:none” (added by Gravity Forms). Then I went back to the source code, realised the Post Update plugin deletes meta values if you check the “Unique Custom Field?” box in the field settings. By unchecking this box, my data is safe now.


As to the post tags, I had to add it to the form and applied a CSS class “gform_hidden” to get it hidden. (If I just set it to “Admin Only”, it still got wiped out after form submission.)

Post Tags field in Gravity Forms

So lessons learned here:

  1. When using conditional logic for “custom fields” and would like to work with the Post Update plugin, DO NOT check the “Unique Custom Field?” box or you’ll lose the data while user who can’t see these fields update the form.
  2. Even if you just let admins to apply post tags at the post editing screen, the post tags field has to be added to the forms. You must hide it with the CSS class “gform_hidden“, set it visible to “Admin Only” won’t work, it would still get wiped out.

Changing Arguments For The Built-In Taxonomies In WordPress

With the following snippet you can change arguments for the built-in taxonomies in WordPress:

To modify arguments for the built-in taxonomies might not be a good idea unless you really know what you’re doing. I’m doing this because (not sure since when) now WordPress won’t let me display links from the link_category taxonomy (remember Links Manager?) on its own template page (taxonomy-link_category.php).

One symptom I’ve noticed is that when I visited the link_category term page (like visiting http://SITE.COM/?link_category=links), it showed the index page template but not 404 page, which meant such route did exist just the data couldn’t be shown public.

After some time-wasting trial and error I realized it’s the default arguments keep the template from working. And the snippet above did the trick perfectly.

Hope it could save someone thirty or so minutes someday in the future. 😉

Switch To Another Theme On Certain Pages In WordPress

I wrote a tiny WordPress plugin to switch themes between certain pages and the rest ones of a site. Check the gist out:

Here’s my brief explanation:

  1. Line 15-19: We need to hook to these two filters (stylesheet and template) to let WordPress know we’d like to use another theme other than the one has been set. I’d recommend we do such calls in setup_theme action. Maybe you could use other actions instead, if you find one, just let me know.
  2. Line 21-28: This is our filter function to change stylesheet WordPress would use. If you’re going to use a child theme like me, set your child theme here, or just use your theme.
    And the most important part is how I tell WordPress to switch themes on “certain pages”. I specify them by checking the $_SERVER['REQUEST_URI'] param.
  3. Line 30-37: Basically works like the previous one, just it changes the template (parent theme).

The use case of this plugin is that for a client site I built and maintain, I need to enable a survey form which will be built by Gravity Forms. Though it won’t be too difficult to build such form, I felt lazy to write some more CSS to style it. I was just wondering, it would be so much less work for me to do if I can use the default WordPress theme to display the form.

And after some googling, it’s done! I hope it could help you with your needs too.