Sep 202014

I’m writing code for a wordpress plugin of mine, and needed for the get_posts() function to return ALL posts. Here’s what I was using before:

$args = array(
‘post_type’ => ‘post’,
‘post_status’ => ‘publish’,
$posts = get_posts($args);

According to the wordpress documentation, the ‘posts_per_page’ option for this function has a default value of 5, meaning you’ll get at most 5 results back. I looked to see if there was a way to show all posts, and I couldn’t find it documented anywhere.

However, I did see some people provide code that had that value set at -1. I thought it might be a way of specifying no limit, so I tried it, and it’s working. Here’s what I use now:

$args = array(
‘post_type’ => ‘post’,
‘post_status’ => ‘publish’,
‘posts_per_page’ => -1
$posts = get_posts($args);

It may not be a documented features, but it’s working for now. Give it a shot if you’re looking to have get_posts() return an unlimited number of posts.

Nov 132013

Last week I had a site that Google was linking to securely, ie the https://www… instead of http://www.  I had a SSL cert set up on the site, but not all the content was being served over https, which was causing errors. So if you searched for my site on Google and clicked on the link that came up, you were seeing a broken site!

I figured there’d be a setting in Google Webmaster Tools that would allow you to specify the preferred protocol for your site. But there’s not. How did Google even know to use https in the first place?

To see if Google has indexed any of your urls securely, perform this search: “ -inurl:http”. I had several showing up.

It turns out that once Google knows you have https (all it takes is one link), they’ll prefer it over http and update all of their references to you. You can use a 301 redirect, but that seems like overkill. I searched and searched for a better solution, and finally found a solution to tell Google I wanted to use the non-secure version of our site as our home page.

The solution is this: Use the canonical tag on all your pages, pointing to your http page. That’s it. If your site is a wordpress blog, there are some plugins that can help you do this.

It’ll take a couple days for Google to recrawl you and honor your preferred urls specified in your canonicals, but it’ll work.

Here’s the original forum post that had the solution: StackExchange

Aug 052013

I know it sounds weird to have a filter for ALL incoming mail, as it’s not really filtering anything. But sometimes there are actions you want Gmail to take on all of your email. This could include not sending anything to the spam folder, forwarding the email to a different address, or marking it with a label.

There is not ‘catch all’ setting, so you have to use a simple trick. When setting your filter search options, enter a nonsense value in the “Doesn’t have” field. Example: ‘ash87slkjhsdkjfsd8fsdf99889’. No real email coming in should ever have that value in the mail, so that will essentially match all your new mail.

Seems kinda silly, but it works! Here’s a screenshot:


Hope that helps!

Mar 312013

We just got a new server on HostGator, and upon accessing some php files we had uploaded, we got this error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I looked at the server logs in /usr/local/apache/logs/error_log to see:

[Mon Mar 25 16:28:50 2013] [error] [client] SoftException in Application.cpp:256: File “/home/user1/public_html/folder1/index.php” is writeable by group

[Tue Mar 26 09:05:26 2013] [error] [client] SoftException in Application.cpp:601: Directory “/home/user1/public_html/folder1″ is writeable by group

Turns out, this error can be caused by suEXEC, a security feature that checks permissions of files before running them to make sure there are no vulnerabilities. You can turn it off in WHM under the Service Configuration area, “Configure PHP and suEXEC”

To fix this error:

Run these 2 commands. This will adjust the permissions of php files and directories if they had been set incorrectly.

find . -name ‘*.php’ | xargs chmod 644
find . -type d | xargs chmod 755

To prevent this error:

To stop this from ever happening in the future, you have to adjust the umask of the user. Umask sets the default permissions on any new files. Just type ‘umask 0022’ at the command line while you’re that user. HostGator originally has it set at 0002.

Good luck, let me know if that fixes your problem!

Jan 142013

That google trusted store badge looks pretty awesome, and I’m sure it’s a way to convert more visitors into customers. I thought it was just a matter of providing some documentation about your business’s policies and promising to have good support, but no – there are minimum eligibility requirements. At the time of this post, you must meet the following:

  • Minimum Order Volume: 500 orders/month on a rolling 28-day basis
  • Trackable Orders: >50% of orders trackable via supported carriers (UPS, FedEx, USPS)
  • On-Time Shipping: >90% of orders shipped on time
  • Consistently excellent service and very high customer satisfaction with end-to-end experience – few customer escalations, fast issue resolution

If you meet that then getting the badge is just a matter of signing up at Good luck!

Dec 312012

I came across some interesting behavior when calling document.write multiple times. The first time I called it was fine, but if I called it again in a setTimeout, the page would go blank. Turns out that it’s because once the page loads and fires document ready event, it doesn’t know where the current cursor is. This causes the browser (happens in at least IE and FireFox) to start the page over from scratch, thus showing a blank screen.

So, don’t make the javascript call document.write after the page has loaded!

See this for more information

Hope that helps you!

Dec 082012 is a website that allows you to purchase common databases at reasonable prices. What sets them apart from the rest is that they are EASY!

All of their databases are packaged with something called the EZDB system. I’m not sure what that is, but I can vouch that it made my database installation super simple. After you download the database, just find the file for your database (at the moment the support mysql, microsoft sql server, microsoft access, oracle, excel and CSV – comma separated values). That file will be ready to use as is or it will be the only file you need to set up your database (ie, sql insert statements that you just need to upload to your server).

Anyway, super simple. I got a US census demographics by zip code and it has been great!

Hope that helps anyone looking for marketing or research databases by zip!

Dec 082012

I wanted to remove ALL javascript and css from the head, but still call the wp_head function since it loads other stuff (meta, plugins, etc). Most advice tells you to use wp_deregister_script() and wp_deregister_style() to individually remove each file, but you need to know the name they were registered as, which requires you to dig deep into code. I just wanted something that removed all of them, cleared it out. I couldn’t find a function that did this, so I made a workaround.

This is not supported by WordPress, so it may not work in the future, but works as of now. Also this only works if the css and js were added the correct way (via wp_enqueue_script() and wp_enqueue_style()) – if the styles and scripts are hardcoded in the theme, you’ll have to edit those theme files directly.

    global $wp_scripts, $wp_styles;
    $wp_scripts = new WP_Scripts();
    $wp_styles = new WP_Styles();

Hope it helps you!

Sep 062012

Clicktale’s free plan only allows you to see 2 page views per recording session. And that’s simply not enough to see if Clicktale is worth paying for. How are you supposed to decide whether to upgrade to a paid plan if you haven’t been able to gauge the power of the tool?

So, while you’re trying clicktale out, use this javascript bookmarklet to reveal the hidden page views. It simply hides the box that covers the screen after 2 pages have been seen. Drag the link below up to your browser bar, then you’ll have a button that you can press at the beginning of every playback which will prevent the box!

Unhide Clicktale

I DO NOT CONDONE USING THIS TO GET CLICKTALE FOR FREE. Please only use it as a tool to help you decide whether you want to purchase a real plan.

Note: I’ve only tested this in Google Chrome. If it works/doesn’t work in other browsers please let me know.

Jun 272012

Today I was modifying someone else’s file when I noticed that when I uploaded it to the server it displayed horribly. All whitespace was gone, and in the place of newlines was ^M characters. Here’s a snapshot of how the file looked when I uploaded.

If I viewed it with ‘more filename.php’ I didn’t see the ^M but it looked as if the whole file was on one line, and some characters had been replaced by {. Strange.

It does not affect the server’s ability to run the file, but it does make maintenance a nightmare if you ever have to edit the file in the future.

I had been using Notepad++ (notepad plus plus) to edit it, and I had never had this problem with any of my files. Turned out the file had originally been made on a Mac, which caused these weird characters to show up (sometimes it happens on Windows too).

Luckily there’s an easy fix. With the file open in Notepad++, simply go to the Edit menu -> EOL Conversion -> Windows. It might also work if you choose Unix too. Then save the file, re-upload and you’re golden!

Hope that helps!