Custom Queries in WordPress

I have been researching how to create custom queries in WordPress for a potential upcoming project. What I mean by custom is the ability to query the database and display non-WordPress data on the screen. During my process of researching this and trying different things, I have discovered two things…

1. WordPress does not have the ability to easily query a table outside of it’s installation database. Or if it does I haven’t been able to find it. Everything I have read seems to point to having to merge any existing database with the WordPress installation database. This solution is not that big of deal for me.

2. WordPress DOES offer the ability to query the data that is in the installation database and display it any way you need to. I have outlined below a brief tutorial based on my findings.

This explanation uses PHP. The reason for this is because I host this on a Linux server.

The first thing we need to do is make sure our WordPress site can parse out PHP that will be inserted into a post or a page. There are several plug-ins for this. I am using EXEC-PHP. It was easy to install and I have had no issues with it.

Now that you can render PHP, let’s move on.

This example will use a very basic query based on the “users” table. However, you can use any table in the database. This should get you going in the right direction.

<?php
global $wpdb;
$user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");?>
<p><?php echo 'user count is ' . $user_count; ?></p>

The biggest thing to note here is:

global $wpdb;

Without this line, the query won’t work. There are several things you can do with $wbdp and you can find more information here.

I know this is very basic, but this is just the beginning. I can’t really go into details of the project I am researching this for, but if the project gets the green light, there will be many more posts as I overcome the hurdles. Anyway, I hope this helps someone.

The Virtual Red Pen

I was sitting at work yesterday and my wife Karen called me. She was calling to inform me that I had a spelling typo and a grammatical typo on this site. This is not a big deal to me because she has always been my virtual editor. And 9 times out of 10 she will find something. The fact that I had typo’s is kind of ironic because there are two things that will cause me to leave a web site quickly. The first is poor programming. My frustration with that is a blog post all on it’s own. The second thing however, are typos. If I am visiting an e-commerce website, for example, and there is a typo, that makes me wonder if they don’t pay attention to the small details, how are they going to handle customer service if I have a problem. I know this sounds hypocritical, but I would not hold it against anyone if they saw a typo on my site and left. So this conversation sparked an idea…The Virtual Red Pen!

The idea is rather simple. Build an application that would allow visitors to mark up a web site showing where the typo’s are and then assign a grade to that web site based on the number of typo’s that were found.

It would work much like the google SideWiki, but instead of being in a tool bar on the side of the page, the information would be displayed right on the page.

It should also notify the web site owner that mistakes were found and give them a chance to correct them.

I know what you are thinking… You are thinking this is a great idea, but how is it going to make money?

Good question! And the answer is the same way everything makes money on the internet….Advertising!

When a user mouses over a mistake that is noted, a little pop up would appear informing the user “This typo is brought to you by ~Insert Company Name and Catchy Slogan Here~”

With every great idea, generous investors are needed. So if you are a generous investor and know a good idea when you see one, please contact me. If not, I may have to go on ABC’s hit television show “Shark Tank“.

Word Press vs. Posterous

I use both, Word Press and Posterous. This site is built on Word Press and the blog for my day job is built on Posterous. While playing with the new custom themes feature in Posterous today, the question came up how does it compare to Word Press.

Personally, I don’t think it is on the same level as Word Press. Both serve specific functions and while they share functions, they really are not on the same level.

I have recently become a Word Press convert and have to say I absolutely love it. It is incredibly easy to build a web site on their platform with more plug-ins then you can count. Word Press includes just about every feature you would want in a content management system, and some you would not think about, but are glad they are there. It is the perfect tool for anyone wanting to build more then a blog. Word Press originally started as a blogging tool, but personally, now it seems like overkill for just a blog.

Posterous, however, is perfect for that user that would like a very simple and easy to use blogging tool. It is so easy to use that if you can send an email, you can use Posterous. They have several cool features that most blogging tools do not include.

The best feature they have is that you can post from just about any medium you can think of. You can post from their interface, your phone, and email. You can embed just about any type of media into the post and Posterous will convert it for you. When sending a post from email, it is as simple as attaching the media file to the email.

The newest feature Posterous has added is custom themes. You can now customize the look of your Posterous page. This is something I started doing today and found it very easy to navigate and make changes. If you are a business or you have a group of contributors, you can have several people contribute to the same account using different email address or phone numbers.

So in summary, I like both tools for different reasons. If you need a very simple almost no frills blogging engine, check out Posterous. If you need something a little more robust, then Word Press is worth a look. But don’t take my word for it. Check them both out and then decide which one fits your needs. Maybe both will fit your needs. You won’t know until you try them.

The President to address our children

Today is the day that President Obama will address the students of this nation. So naturally, there is a lot of talk about in the media and in the blogosphere. I have been reading articles that say the President should not be allowed to address our children, that there is a hidden political agenda, and my personal favorite… that he should focus on more important things.

In order to form an opinion on this I went and read the speech the President intends to give. After reading the speech, I realized one very important thing… It’s not the speech that has people up in arms. It’s the person giving the speech that is the problem.

There is nothing “political” in the speech. There is no Kool-Aid to drink with the exception of encouraging the children of this nation to get an education and go after their dreams.

I wonder if this speech was being given by a pastor, or a principal of a school, or a grandfather, would there be an issue? I have to think there wouldn’t be an issue and the person giving the speech would be commended for taking such an interest in the future of our children.

My final concern about this whole thing is schools and school districts that are “banning” their students from watching the President speak live today. It blows my mind how people would outright tell children that even though the message is encouraging, they are not allowed to watch it while it happens.

Let me wrap this up, I don’t care who you voted for because this is not about politics, contrary to what some may think. This is about encouraging the future of this country to stay on track, work hard, and not to give up on their dreams.

So parents, teachers, school board leaders, let the future of our country be encouraged for a change.

I will now come down off my soap box and return you to your regularly scheduled program.

Abbott and Costello

Let me preface this by saying that I did not write this (although I wish I had). I received this in an email and thought it was funny enough to share…

———————————————————————–

ABBOTT AND COSTELLO UPDATED VERSION ON BUYING A COMPUTER LIKE ‘WHO’S ON FIRST’

You have to be old enough to remember Abbott and Costello, and too old to
REALLY understand computers, to fully appreciate this.

If Bud Abbott and Lou Costello were alive today, their infamous sketch,
‘Who’s on First?’ might have turned out something like this:

COSTELLO CALLS TO BUY A COMPUTER FROM ABBOTT 2009 VERSION
ABBOTT: Super Duper computer store.. Can I help you?
COSTELLO: Thanks I’m setting up an office in my den and I’m thinking about buying a computer.
ABBOTT: Mac?
COSTELLO: No, the name’s Lou.
ABBOTT: Your computer?
COSTELLO: I don’t own a computer. I want to buy one.
ABBOTT: Mac?
COSTELLO: I told you, my name’s Lou.
ABBOTT: What about Windows?
COSTELLO: Why? Will it get stuffy in here?
ABBOTT: Do you want a computer with Windows?
COSTELLO: I don’t know. What will I see when I look at the windows?
ABBOTT: Wallpaper.
COSTELLO: Never mind the windows. I need a computer and software.
ABBOTT: Software for Windows?
COSTELLO: No. On the computer! I need something I can use to write proposals, track expenses and run my business. What do you have?
ABBOTT: Office.
COSTELLO: Yeah, for my office. Can you recommend anything?
ABBOTT: I just did.
COSTELLO: You just did what?
ABBOTT: Recommend something.
COSTELLO: You recommended something?
ABBOTT: Yes.
COSTELLO: For my office?
ABBOTT: Yes.
COSTELLO: OK, what did you recommend for my office?
ABBOTT: Office.
COSTELLO: Yes, for my office!
ABBOTT: I recommend Office with Windows.
COSTELLO: I already have an office with windows! OK, let’s just say I’m sitting at my computer and I want to type a proposal.. What do I need?
ABBOTT: Word.
COSTELLO: What word?
ABBOTT: Word in Office.
COSTELLO: The only word in office is office.
ABBOTT: The Word in Office for Windows.
COSTELLO: Which word in office for windows?
ABBOTT: The Word you get when you click the blue ‘W’.
COSTELLO: I’m going to click your blue ‘w’ if you don’t start with some straight answers. What about financial bookkeeping? You have anything I can track my money with?
ABBOTT: Money.
COSTELLO: That’s right. What do you have?
ABBOTT: Money.
COSTELLO: I need money to track my money?
ABBOTT: It comes bundled with your computer.
COSTELLO: What’s bundled with my computer?
ABBOTT: Money.
COSTELLO: Money comes with my computer?
ABBOTT: Yes. No extra charge.
COSTELLO: I get a bundle of money with my computer? How much?
ABBOTT: One copy.
COSTELLO: Isn’t it illegal to copy money?
ABBOTT: Microsoft gave us a license to copy Money.
COSTELLO: They can give you a license to copy money?
ABBOTT: Why not? THEY OWN IT!
(A few days later)
ABBOTT: Super Duper computer store. Can I help you?
COSTELLO: How do I turn my computer off?
ABBOTT: Click on ‘START’…………..

Poor man’s guide to calendar synchronization

A few weeks ago I was on a mission to figure out a way to synch the calendar on my iMac in the office to the calendar on the MacBook I use for working from home. Considering they were both MAC, the obvious solution was…

mobileme

This is a good solution with several features. The problem for me was that I only needed the calendar synchronized. So I couldn’t see the value in spending the $99 a year just for the calendar option.

So the search continued…

I turned to everyone’s favorite microblogging site Twitter and asked if anyone knew of a good solution. I received several ideas, but none that seemed to fit what I was trying to do.

That brings me to Plaxo. I realized that Plaxo offered an automated synchronization application for calendars, and best of all it is FREE. Below are the steps to set this up.

  1. If you don’t already have an account with Paxo, click here to set one up. If you do have an account, go here and log in.
  2. Once logged in, under the “More” tab, click on Calendar.
  3. At the bottom of your screen you will see an option to “add synch points”. Click this and select the type of synch point you would like. In my case, it was Mac OS X.
  4. Follow the on screen instructions for the type of synch point you would like. And install any required application. In the case of a MAC, there is a small app that runs in the background.

Simple, easy, and FREE. The only issue I ran into was once installed and running, I would get the same plaxo update displaying on my screen several times a day. The solution was easy. Under the configuration settings, uncheck “Show Pulse Notifications”.

This may not be the solution for everyone, but it was a great solution for me.

The only thing we have to fear, is fear itself.

Ok, I will admit the title is a tad bit corny. Also, something to note, I did intend to post an entry today, however this was not the post I had intended. That post will be coming at a later date. So on to the post…

I am very intrigued my Max Lucado’s book FearLess. Before I get into that, let me back up a lttle.

I serve on the Wellness committee where I work. One of our latest projects was starting a quarterly book club. Because of this, we had a rep from Thomas Nelson Publishing come in and show what they could offer. Which it turns out they could offer a lot of things.

Anyway, it was during this meeting where I could hear a little voice telling me that I needed to become more active on this committee. The voice was telling me I needed to offer to teach a class as another option to the book club. Don’t get me wrong, I think the book club is a good idea, I just think that some people find the term “book club” to be a bit nerdy.

So, back to the meeting… Without a doubt I knew that little voice was God telling me these things. How did I know this? Because anyone who knows me, knows that I am terrified of speaking in front of groups of people. All through out the meeting, in my mind, I kept saying no I can’t do it. Of course by now I am trying to work a deal with God. I starting thinking OK Lord, if you really want me to do this, you are going to have to prove it to me.¬† And here is where it all comes together.

The sales rep then proceeds to pull out Max Lucado’s book FearLess. In my mind I am thinking “Are you kidding me???”.

With that, I proceed to tell them my idea. Now as of right now, no class has been scheduled and if one is, I am not sure if it will be a study of this book. So who knows.

Now about the book. I would like to say I have started reading it, but I haven’t. It has been sitting on my night stand for the past several days. I do plan to read it and hopefully soon I will start it. Perhaps that is what this post is for, to keep me accountable and actually read it. Even though I have not cracked the book open yet, I think it is a subject worth studying. I think I may talk to my pastor about teaching it on Wednesday evenings as well. Like I said, I may never lead a study about this book or the topic of Fear, but I am determined to read the book.

Below is some information about the book including a 4 part video town hall that Max did about that book.

Consistency

I have been thinking about consistency a lot lately. Especially when it comes to brand management. In this thinking I have noticed I am the most inconsistent person I know. At least when it comes to the different social media websites I use. Normally this wouldn’t be a bad thing, except I spend my day telling people they need to have consistency across all their marketing platforms.

So in an effort not to be a hypocrite, it is my goal to become consistent across all social media platforms that I use. It is in that light that DigitalMcGrath.com was born. Along with this, I have changed my Twitter user name to match.

On this blog you will find posts about what ever I may be thinking at the time. These could range from thoughts about my family, work, things I may be trying to help my church and there online brand, and whatever else enters my mind.

I will say that we are getting ready to move next month, so more then likely there will be posts about that fun and exciting time.

Subscribe to RSS Feed Follow me on Twitter!
Stop SOPA