This plugin code above (Meta to Cat) is exactly what I need but I get a console error showing in Firebug and no action!
missing ; before statement
dispatchCallback(null, "oninit", "onInit")tiny_mce_gzip.php (line 97)
onLoad()tiny_mce_gzip.php (line 63)
onLoad()tiny_mce_gzip.php (line 44)
[Break on this error] var meditation-and-buddhism_cat_id = 'in-category-6';\n
The code as I 'translated' the plugin for my categories is:
<?php
/*
Plugin Name: Meta to Cat
Version: 0.1
Plugin URI: http://labs.dagensskiva.com/
Description: Creates a cat for a specific key.
Author: Henrik
*/
function set_cat_by_meta () {
if (preg_match("/\/post/", $_SERVER['PHP_SELF'])) {
?>
<script language="JavaScript" type="text/javascript">
document.onload = p2m_init();
// Hook functions to the key
function p2m_init () {
$('Event Type').onchange = function () {
// Get the value in the select list
var cat_value = $('Event Type').value;
// The 'Meditation and Buddhism' category...
var meditation-and-buddhism_cat_id = 'in-category-<?php echo get_cat_id('meditation and buddhism'); ?>';
if (cat_value == 'Meditation and Buddhism') $(meditation-and-buddhism_cat_id).checked = true;
else $(meditation-and-buddhism_cat_id).checked = false;
// The 'Buddhism' category...
var buddhism_cat_id = 'in-category-<?php echo get_cat_id('buddhism'); ?>';
if (cat_value == 'Buddhism') $(buddhism_cat_id).checked = true;
else $(buddhism_cat_id).checked = false;
// The 'Meditation' category...
var meditation_cat_id = 'in-category-<?php echo get_cat_id('meditation'); ?>';
if (cat_value == 'Meditation') $(meditation_cat_id).checked = true;
else $(meditation_cat_id).checked = false;
// The 'Retreats' category...
var retreats_cat_id = 'in-category-<?php echo get_cat_id('retreats'); ?>';
if (cat_value == 'Retreats') $(retreatsr_cat_id).checked = true;
else $(retreats_cat_id).checked = false;
};
$('Level').onchange = function () {
// Get the value in the select list
var cat_value = $('Level').value;
// The 'Newcomer' category...
var newcomer_cat_id = 'in-category-<?php echo get_cat_id('newcomer'); ?>';
if (cat_value == 'Newcomer') $(newcomer_cat_id).checked = true;
else $(newcomer_cat_id).checked = false;
// The 'Friend' category...
var friend_cat_id = 'in-category-<?php echo get_cat_id('friend'); ?>';
if (cat_value == 'Friend') $(friend_cat_id).checked = true;
else $(friend_cat_id).checked = false;
// The 'Sangha' category...
var sangha_cat_id = 'in-category-<?php echo get_cat_id('sangha'); ?>';
if (cat_value == 'Sangha') $(sangha_cat_id).checked = true;
else $(sangha_cat_id).checked = false;
};
}
</script>
<?php
}
}
add_action('admin_footer', 'set_cat_by_meta', 11);
?>
Any ideas what I've done wrong? (there are no extra whitespaces in my custom tags) I can't see where there could be another ; put! I've tried changing single quotes to double quotes and adding extra double quotes but it looks like the php is being processed ok.
I'm not at all familiar with javascript so I may have made a silly mistake - I thought it might be to do with repeating the code for the second custom tag but that does not appear to be the case through testing.
Maybe there is a conflict with TinyMCE? I am using WordPress 2.3.3 on xampp.