Variable not returning?

Confusing problem. I have a function which creates a link to edit a post you’ve just created.

It calls another function which retrieves the post after you’ve made it.

The problem I’m having is that the variable won’t return from the second function. It is properly filled, I var_dump’d at multiple stages in the function getSinglePost and the data is returned (a mysql array). But after returning to the function getEditLink it’s empty and causes an error.

I’m not sure what the error is, can anyone help?

The first line in getEditLink goes -> getSinglePost -> getEditLink -> Continue.

function getEditLink( $post_ID = 0) {
	if (!$post = getSinglePost( $post_ID ) ) {

		$action = '&action=edit';
			echo"This is our var dump ".var_dump($post);
	$post_type_object = get_post_type_object( $post->post_type );
	if ( !$post_type_object )

	return sprintf($post_type_object->editlink . $action, $post->post_id);
function getSinglePost($post, $filter = 'raw') {
	$null = null;

	if ( empty($post) ) {
		if ( isset($GLOBALS['post']) )
			$_post = & $GLOBALS['post'];
			return $null;
	} elseif ( is_object($post) && empty($post->filter) ) {
		$_post = sanitize_post($post, 'raw');
	} else {
		if ( is_object($post) )
			$post_id = $post->post_id;
			$post_id = $post;

		$post_id = (int) $post_id;
		echo $post_id;
		if (!$result = mysql_query("SELECT * FROM posts WHERE post_id = $post_id LIMIT 1"))  {
				return null;
		else {
			$_post = mysql_fetch_array($result);
			 sanitize_post($_post, 'raw');
		return $_post;

Just to let readers know, this is Solved, somewhat. It WAS returning, just for whatever reason I couldn’t access it using $post->post_type. Had to use $post[‘post_type’]

be very careful there, you’re getting close to accessing the $_POST predefined array…

and yes, there is no such thing $post->anything. You’re returning an array, not an object.

Do you mean close as in if i added an “_” prefix? I can change the name if it is a danger.

Do you know why I’m not returning an object? Does it matter if it is an object or array?

            [B][COLOR="Red"]$_post[/COLOR][/B] = mysql_fetch_[COLOR="Blue"]array[/COLOR]($result);

danger will robinson :stuck_out_tongue:

Do you know why I’m not returning an object? Does it matter if it is an object or array?

Because you defined it as an array in the above line of code?

Ugh. I hate programming.

I will also change that variable, thanks StarLion.