<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DigitalMcGrath &#187; blogging</title>
	<atom:link href="http://digitalmcgrath.com/tag/blogging/feed/" rel="self" type="application/rss+xml" />
	<link>http://digitalmcgrath.com</link>
	<description>Digital McGrath</description>
	<lastBuildDate>Sun, 11 Mar 2012 21:06:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Custom Queries in WordPress</title>
		<link>http://digitalmcgrath.com/custom-queries-in-wordpress/</link>
		<comments>http://digitalmcgrath.com/custom-queries-in-wordpress/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 19:57:00 +0000</pubDate>
		<dc:creator>digitalmcgrath</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://www.digitalmcgrath.com/?p=168</guid>
		<description><![CDATA[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&#8230; 1. WordPress does not have [...]]]></description>
			<content:encoded><![CDATA[<p>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&#8230;</p>
<p><strong>1.</strong> WordPress does not have the ability to easily query a table outside of it&#8217;s installation database. Or if it does I haven&#8217;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.</p>
<p><strong>2.</strong> 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.</p>
<p>This explanation uses PHP. The reason for this is because I host this on a Linux server.</p>
<p>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.</p>
<p>Now that you can render PHP, let&#8217;s move on.</p>
<p>This example will use a very basic query based on the &#8220;users&#8221; table. However, you can use any table in the database. This should get you going in the right direction.</p>
<pre class="wp-code-highlight prettyprint">&lt;?php
global $wpdb;
$user_count = $wpdb-&gt;get_var(&quot;SELECT COUNT(*) FROM $wpdb-&gt;users;&quot;);?&gt;
&lt;p&gt;&lt;?php echo 'user count is ' . $user_count; ?&gt;&lt;/p&gt;</pre>
<p>The biggest thing to note here is:</p>
<pre class="wp-code-highlight prettyprint">global $wpdb;</pre>
<p>Without this line, the query won&#8217;t work. There are several things you can do with $wbdp and you can find more information <a id="aptureLink_MB24awqG3b" href="http://codex.wordpress.org/Function_Reference/wpdb_Class">here</a>.</p>
<p>I know this is very basic, but this is just the beginning. I can&#8217;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.</p>
]]></content:encoded>
			<wfw:commentRss>http://digitalmcgrath.com/custom-queries-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

