Accessing Wordpress Databases

Posted in codex on February 1st, 2010 by Cam – Be the first to comment

One of the more useful things I’ve learned while developing with Wordpress is the use of the $wpdb class which allows you to use the Wordpress database functions in your plugin without including the header and footer. This is useful when you’re using a bit of jQuery or AJAX to submit a form and get a call back w/o getting all the Wordpress headers and HTML.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Wordpress root directory (from plugin's directory)
$path = '../../../';
 
include_once($path . 'wp-config.php');
include_once($path . 'wp-load.php');
include_once($path . 'wp-includes/wp-db.php');
 
function attachments() { 
    global $wpdb;
 
    $sql = "SELECT * FROM ".$wpdb->posts." WHERE post_type = 'attachment'";
    $rows = $wpdb->get_results($sql); 
    $html = '';
 
    foreach($rows as $row) { 
      $html .= '<div><a href="'.$row->guid.'">'.$row->post_title.'</a></div>';
    }
 
    return $html;
}
 
// Outputs a list of the attachments (media files)
echo attachments();
 
//
  • Share/Bookmark

TinyMCE in WordPress Plugin

Posted in codex on January 12th, 2010 by Cam – Be the first to comment

I’ve been to the edge of the internet and back, before I found this tidbit of code that will allow you to use TinyMCE in your WordPress plugins!

1. Add the following code to your plugin

1
2
3
4
5
6
7
8
9
10
11
12
add_filter('admin_head','myplugin_tinymce');
 
function myplugin_tinymce() {
    wp_admin_css('thickbox');
    wp_print_scripts('jquery-ui-core');
    wp_print_scripts('jquery-ui-tabs');
    wp_print_scripts('post');
    wp_print_scripts('editor');
    add_thickbox();
    wp_print_scripts('media-upload');
    if (function_exists('wp_tiny_mce')) { wp_tiny_mce(); }
}

2. Call the editor in your plugin

1
the_editor($content_to_load);
  • Share/Bookmark

Never Stop Learning

Posted in codex on October 30th, 2009 by Cam – Be the first to comment

I’ve been a developer for over 10 years now and I stumbled upon an extremely simple bit of coding that I’ve never either seen or realized was out there. It’s so simple that I feel like a complete n00b for not knowing this! read more »

  • Share/Bookmark

IM’s Place at Work

Posted in articles on September 30th, 2009 by Cam – Be the first to comment

IM at work
IM has the immediacy of telephone without the interruption, and the convenience of email without the delay. For years I’ve been an advocate for instant messaging in the work place so I figured I’d take a few minutes and explain why I feel IM should be implemented and how!

read more »

  • Share/Bookmark

Destination: Web

Posted in articles on September 15th, 2009 by lisa – Be the first to comment

destination

I like to consider myself pretty tech-savvy, as are most of my colleagues and friends. I’ve also found that the Internet is an awesome way to connect with people – family, friends, clients, potential clients – whether it be through social networking, email, or our website. As we built our small business, having a website and web presence seemed to be a “no brainer”. I was shocked to learn that we are in the minority of small business owners with a website or using social media for networking and promotion.

read more »

  • Share/Bookmark