wordpress get posts by id

Simple solution for the wordpress `get_posts` function to get a list of posts by post id / an array of post ids:

$args = array( ‘post__in’ => array(34,36) );
$posts = get_posts($args);

It’s always really hard for me to remember that crazy `post__in` with a double underscore between `post` and `in`.

Posted in Tech Tips | Tagged | Leave a comment

knife bash completion – with fixed environments autocomplete

[Steven Danna](https://github.com/stevendanna/knife-hacks) has written the best `knife` bash completion script that I’ve seen for use with managing chef servers and the chef software by opscode.

Update: Steven has now made an update so this is working!

There was always one little thing wrong with it though:

> knife environment edit (etc) would not autocomplete – it would give an error

The error was:

-bash: _chef_environments: command not found

The solution is pretty simple – you just need to edit the script and transpose two letters that were a typo from the [knife_completion.sh](https://github.com/stevendanna/knife-hacks/blob/master/shell/knife_completion.sh) file:

_chef_environemnts

should actually be:

_chef_environments

The difference is hard to spot but it’s key.

Two other scripts for knife completion (that I don’t like as much) are [this one by avishai-ish-shalom](https://gist.github.com/avishai-ish-shalom/1050685) and [a spinoff by vindimy](https://github.com/vindimy/dotfiles/blob/master/bash-completion/knife.sh) – I think they are slower and not as user friendly.

If you use `zsh` instead of `bash` there is also a [zsh knife](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/knife) plugin which is part of `oh-my-zsh` that seems pretty good.

Posted in Server Administration, Tech Tips | Tagged , , | Leave a comment

Cpanel Set Default Webpage: defaultwebpage.cgi

On new `cPanel` servers if you try and access the site via IP or a domain name that does not yet have an account, you’ll be greeted with the `Default Website Page` response and redirected to `/cgi-sys/defaultwebpage.cgi`

This is a little bit annoying because the page will set an expires time that is not immediate. That means in most browsers when you fix the error on your server (if you are the cPanel administrator) and try to check the site again, you’ll be automatically redirected to `/cgi-sys/defaultwebpage.cgi` and get the “Default Web Site Page” message even if your site has been correctly fixed. So that means you need to clear your browser’s cache each time it is messed up and you attempt a fix – this is a little annoying.

What happens is that there is a default `index.html` file that uses `meta refresh` tag to forward you along to `/cgi-sys/defaultwebpage.cgi`

The default index file is located at:

/usr/local/apache/htdocs/index.html

I’ve updated mine so it just displays an error on that page. You can even copy and paste the generated output from the `defaultwebpage.cgi` file into the index.html file (make a backup first if you’d like) and then the page will just show the error text and not redirect you to the `cgi-bin` directory and refuse to re-check the homepage without clearing the cache.

Once you’re no longer being forwarded to the cgi-bin directory, you can just do some `control+r` or `f5` to tell the browser to reload the page to check and see if your cPanel settings have been fixed.

Posted in Tech Tips | Tagged | Leave a comment

ssh command returns “stdin: is not a tty”

If you run a command via ssh (secure shell) on linux and you get the following output:

stdin: is not a tty

The most common cause is the `mesg y` or similar command found in the file:

/etc/bashrc

###What is mesg ?

> mesg is a Unix command that sets or reports the permission other users have to write to your terminal using the talk and write commands.

###How can I fix this issue?

Option 1 would be to comment out the line.

Option 2 would be to change the line to something like this to only invoke the command when you are actually using a connection with `tty`:

if tty -s; then mesg y; fi

Posted in Linux, Server Administration | Tagged , | Leave a comment

Is there a Tagboard API?

After reading the Tagboard’s TOS and looking for what they say when discussing APIs, there is only a little bit of information. The TOS mentions APIs in regards that “… agree to the terms of the respective application programming interfaces (API) as follows…”

> http://developers.facebook.com/
> https://directory.app.net/app/114/app-net-api-console/
> http://instagram.com/developer/
> https://dev.twitter.com/

So, no, it does not appear that they are allowing API access at this point.

Posted in Tech Tips, Web Development | Tagged | Leave a comment

Google Chrome Dinosaur

With the new version of Google Chrome around version 30.0, your page that shows:

> Unable to connect to the Internet

Will have a cool picture of a dinosaur – a tyrannosaurus rex:

Google Chrome Dinosaur

Posted in Marketing | Tagged , | Leave a comment

Failed to import Media – Solved

If you’re running WordPress and trying to export and import posts with the [WordPress Importer](http://wordpress.org/extend/plugins/wordpress-importer/) you may be getting an error saying `Failed to import Media`

Fortunately this plugin allows error debugging – you just have to turn it on. You can figure out what is causing the error by turning debugging on. There are two methods for this.

First, you can edit the plugin file:

/wp-content/plugins/wordpress-importer/wordpress-importer.php

Change line 17:

define( ‘IMPORT_DEBUG’, false );

to instead be `true`:

define( ‘IMPORT_DEBUG’, true );

You can also edit your `wp-config.php` file and add this line:

define( ‘IMPORT_DEBUG’, true );

That should hopefully help you stop this error:

Failed to import Media – Solved

However since the plugin will attempt to redefine a constant that is already defined it may add errors to your log files, which means you should probably use the first method, or just remove line 17 from the plugin file.

Posted in Web Development | Tagged , | Leave a comment

WordPress: Enable Link Manager

Here is how to turn on and re-enable the link manager in WordPress.

> As of Version 3.5, the Links Manager and blogroll are hidden for new installs and any existing WordPress installs that do not have any links.

WordPress: Enable Link Manager

You might think you need to do something like this:

add_theme_support(‘link_manager’);

But actually the [plugin that re-enables the link manager](http://wordpress.org/plugins/link-manager/) is but a single line of PHP code:

add_filter( ‘pre_option_link_manager_enabled’, ‘__return_true’ );

Which brings back the familiar link manager ( `/wp-admin/link-manager.php` ):

Posted in Tech Tips, Web Development | Tagged | Leave a comment

Adwords: Disable Tablets with full browsers

AdWords Enhanced Campaigns are here and the real reason finally surfaces – Google wants to get rid of the gap between mobile and desktop ads. So much traffic is going mobile, but so many people have opted not to purchase advertising targeted towards mobile devices.

There is a lot of debate about whether or not a lot of conversions occur with mobile devices.

###Don’t be too Quick to Dismiss

> I wish there was an option to control devices more easily in Search as well. However, I wouldn’t be as quick to dismiss tablets. Most of my clients see equal or greater conversions from tablets now, I use my 7″ Nexus all the time to browse and buy products and the data I see from Analytics suggests that the customers of my clients do as well. ([via](https://www.en.adwords-community.com/t5/Improve-results/remove-tablet-advertisement-setting/td-p/149636))

###What’s The Real Reason For AdWords Enhanced Campaigns?

> In addition to increasing adoption rates for mobile advertising in AdWords by greatly simplifying campaign creation, management and reporting for mobile search, Google wants to, eliminate the gap between mobile and desktop CPC’s. ([via](http://www.wordstream.com/blog/ws/2013/02/06/google-adwords-enhanced-campaigns#Mobile%20Bid%20Adjustment%20Factor))

###How To Disable

In adwords choose the “Settings” tab and that is where you can make adjustments. At this time you can select the “Mobile devices with full browsers” segment and tell your bid adjustment to go down 100%.

Adwords: Disable Tablets with full browsers

However, it appears that this unfortunate and annoying behavior that won’t let you opt out of “Tablets with full browsers” is in fact by design from Google and there seems to be no way to get around it. Perhaps post your complaint [here at this discussion board](https://www.en.adwords-community.com/t5/Improve-results/remove-tablet-advertisement-setting/td-p/149636)

Posted in Marketing | Tagged , | Leave a comment

Sublime Text: Remember Position In File

When you close and re-open files in SublimeText there is a way you can get your cursor to go back to the same position. I really like this behavior in VI/VIM called `autocmd` / `BufReadPost` – which is done by editing / changing a configuration file, usually `~/.vimrc` or `/etc/vim/vimrc` and enabling this part:

” Uncomment the following to have Vim jump to the last position when
” reopening a file
“if has(“autocmd”)
” au BufReadPost * if line(“‘\””) > 1 && line(“‘\””) < = line("$") | exe "normal! g'\"" | endif "endif ##Sublime Text In Sublime Text this is done by a plugin called BufferScroll > BufferScroll: Remember, restore and sync scroll, bookmarks, marks, folds and cursors. keys: multiple columns one buffer, follow mode, split, screen, pages, synchronize vertical scrolling

Sublime Text: Remember Position In File

There are two methods for installation:

###Installation with Package Manager

If you’re not yet using Package Manager you may be missing out. At first I thought “ah, who needs that I can just drop in the files I need” but once I started using it I realized that I had been wasting my time by not using it.

Installation is done by [pasting some text into the console](https://sublime.wbond.net/installation) and then once it is installed…

Sublime Text: Remember Position In File

You can use `Cmd+Shift+P` (Windows `Control+Shift+P`) to bring up the “Command Palette” and then install lots of great addons in just a few strokes – like installing `BufferScroll` is as easy as choosing “Package Control: Install Package”:

Sublime Text: Remember Position In File

And then selecting “BufferSroll” from the list of packages that come up! Warning – it may take a few seconds for the list of packages to show up – look at the “loading” status in the status bar (very bottom) of Sublime Text.

See! Wasn’t that easy and totally worth taking a few minutes to install Package Control!?

###Installation without Package Manager

You can also get the source code and installation instructions for a manual installation [over at github](https://github.com/SublimeText/BufferScroll) but I warn you that you will only thank yourself if you choose to install and use Package Manager instead.

Posted in Tech Tips | Tagged | Leave a comment