0) {
$thelist .= '';
foreach ($states as $state) {
$state->name = stripslashes($state->name);
$thelist .= "
";
$thelist .= '';
$thelist .= $state->name. '';
}
echo $thelist;
}
}
function the_state_select() {
global $tableposts, $tablepost2cat, $wpdb, $tablepostmeta;
$type = 7;
$states = $wpdb->get_results("SELECT abbrev, name
FROM states");
$thelist = '';
if (sizeof($states) > 0) {
$thelist .= '';
echo $thelist;
}
}
function get_the_state() {
global $post, $tablepostmeta, $wpdb;
$state = $wpdb->get_results("
SELECT meta_value as state_abbrev, name FROM $tablepostmeta, states
WHERE $tablepostmeta.meta_key = 'state'
AND $tablepostmeta.meta_value = states.abbrev
AND $tablepostmeta.post_id = $post->ID");
return $state;
}
function get_the_state_name($abbr) {
global $wpdb;
$state = $wpdb->get_var("SELECT name FROM `states` WHERE 1 AND abbrev = '$abbr'");
return $state;
}
function list_states(){
global $tableposts, $tablepost2cat, $wpdb, $tablepostmeta;
$target = get_settings('home') . '/index.php?state=' ;
$state_list = $wpdb->get_results("SELECT abbrev, name, COUNT( $wpdb->postmeta.meta_value ) AS state_count
FROM states
INNER JOIN $tablepostmeta ON ( abbrev = meta_value )
INNER JOIN $tableposts ON ($tableposts.ID = $tablepostmeta.post_id )
INNER JOIN $tablepost2cat ON ( $tableposts.ID = $tablepost2cat.post_id )
WHERE post_status = 'publish'
GROUP BY name");
$thelist = '';
if ($state_list) {
foreach ($state_list as $state) {
$link = 'name.htmlspecialchars($state->abbrev) . '">';
$link .= $state->name.'';
$link .= ' ('.$state->state_count.')';
$thelist .= ''. $link . '';
}
}
echo '';
}
function cat2catname($cat) {
if ($cat === '7') {$type_name = 'K-12 Schools';}
elseif ($cat === '8') {$type_name = 'Colleges';
}
return $type_name;
}
function list_state_posts($cat, $state) {
global $wpdb, $tableposts, $tablecategories, $tablepost2cat, $post, $tablepostmeta;
if ($state === '-1' )
{$where = ' ';}
else
{$where = "AND $tablepostmeta.meta_value = '$state'";}
$statelist = $wpdb->get_results("SELECT * FROM $tablepost2cat
LEFT JOIN $tableposts ON $tablepost2cat.post_id=$tableposts.ID
LEFT JOIN $tablepostmeta ON $tablepost2cat.post_id = $tablepostmeta.post_id
LEFT JOIN states ON states.abbrev = $tablepostmeta.meta_value
WHERE post_status = 'publish' AND category_id = $cat $where ORDER BY states.name, $tableposts.post_title ASC");
if ($statelist) {
foreach ($statelist as $state) {
$state_abbrev = $state->meta_value;
if ($state_abbrev != $previous) {
if ($i) {echo '';}
echo ''.get_the_state_name($state_abbrev).'';
echo '';
}
function state_add_query_var($vars) {
// Append state.
$vars[] = 'state';
$vars[] = 'full';
// Don't forget to return the array.
return $vars;
}
function is_state() {
// Get the link category from WP_Query.
$link_category = get_query_var('state');
// If it's empty, return.
if (empty($link_category))
{return false;}
else {return true;}
}
function state_posts_where($where)
{
if (is_state())
$where = " AND wp_postmeta.meta_key = 'state' AND wp_postmeta.meta_value = '" . get_query_var('state')."'".$where;
return $where;
}
function postmeta_join($join)
{
if (is_state())
$join .= " LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)";
return $join;
}
function find_states($id) {
global $wpdb;
$content = $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = '$id'");
if (preg_match_all('//i', $content, $matches, PREG_SET_ORDER)) {
$test = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$id' AND meta_key = 'state'");
if (!empty($test)) {
$output = explode(' ', $test);
} else {
$output = array();
}
foreach($matches as $match) {
$output = array_merge($output, explode(' ', $match[1]));
}
$output = array_unique($output);
$keywords = implode(' ', $output);
if (!empty($test)) {
$results= $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$keywords' WHERE post_id = '$id' AND meta_key = 'state'");
} else {
$results = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$id', 'state', '$keywords')");
}
$content = format_to_post(balanceTags(preg_replace("//i", "", $content)));
$results = $wpdb->query("UPDATE $wpdb->posts SET post_content = '$content' WHERE ID = '$id'");
}
return $id;
}
function order_query($query_string) {
global $doing_rss;
if (!empty($query_string) && !$doing_rss) {
$query_string .= '&orderby=title&order=asc&posts_per_page=99';
}
return $query_string;
}
function state_listing_template() {
if (is_state() && !is_category()) {
load_template(get_template_directory() . '/state.php');
exit;
}
}
add_action('template_redirect', 'state_listing_template', 1);
add_filter('query_string', 'order_query',1);
add_action('edit_post', 'find_states', 1);
add_action('publish_post', 'find_states', 1);
add_action('xmlrpc_methods', 'find_states', 1);
add_filter('query_vars', 'state_add_query_var');
add_filter('posts_where', 'state_posts_where');
add_filter('posts_join', 'postmeta_join');
?>