All pastes #804490 Raw Edit

Mine

public text v1 · immutable
·published 2007-12-03 15:06 UTC
rendered paste body
Got 2 functions :   gengo_get_cat_intro & gengo_id_from_mk.
gengo_cat_intro calls gengo_id_cat.
An ID should be returned.
The problem is that :
-gengo_cat_intro "launches" gengo_id_from_mk.  It works because it echoes 477.
But the line after; I return this ID to use it back in gengo_get_cat_intro; and there, it tells me $intro_id does not exists !!!
Did I miss something ?

THanks !


function gengo_id_from_mk($meta_key,$meta_value,$langcode='',$takeback='0') {
	global $gengo, $wpdb;
	$gengo_default_id = $gengo->blog_default_language_id;
	$gengo_current_id = implode(',', $gengo->language_preference_id);

	if ((empty($meta_key)) || (empty($meta_value))) {
		return;
	}
	if (empty($langcode)) {
		$langsearch = $gengo_current_id;
	} else {
		$langsearch = $langcode;
	}
	$now = current_time('mysql');
	
	$query="SELECT ID
	FROM wp_posts AS posts 
	INNER JOIN wp_post2lang AS post2lang ON posts.ID=post2lang.post_id 
	INNER JOIN wp_postmeta AS postmeta ON posts.ID=postmeta.post_id 
	WHERE posts.post_status = 'publish' 
	AND posts.post_date <= '$now' 
	AND post2lang.language_id IN ($langsearch)
	AND postmeta.meta_key = '$meta_key' 
	AND postmeta.meta_value = '$meta_value'";
	
	$id = $wpdb->get_var($query);
	
	if ($id) {
		echo $id; //OUTPUTS 477
		return $id;
	} else {
		if ((empty($langcode)) && ($takeback=='1')) {
			gengo_id_from_mk($meta_key,$meta_value,$gengo_default_id);
		}
	}
}

function gengo_get_cat_intro($cat) {
	global $wpdb;
	
	$intro_id = gengo_id_from_mk('intro_cat',$cat,'',1);
	if ($intro_id) {
		echo 'success';
	} else {
		echo 'failure';
	}