Support » Fixing WordPress » Quick Theme / Function question

  • I am trying to create a global variable that can be access throughout the entire theme, ie the header, footer and sidebar, single and page .php files.

    I have added the code block below to my function.php file

    function determine_thing($post){
    		global $post;
    		global $thingType;
    		$thingType = "";
    		$id = $post->ID;
    		$thingType = get_post_meta($id,'thingtype',true);
    		$category = get_the_category($id); 
    	    switch ($category[0]->slug)
    			case "thing":
    			$thingType = "a";
    			case "thing2":
    			$thingType = "b";
    			$thingType = "c";
    return $thingType;
    add_action('the_thing', 'determine_thing');

    I believe the registration of this function was successful but i am at a loss of how to call it? I have tried the code block below and its not working. Also will this actually achieve what i want?

    global $post;
    $thingType = do_action('the_thing', $post);

    thanks in advance


Viewing 1 replies (of 1 total)
  • Your function doesn’t ACTUALLY require any arguments since you’re already pulling in the $post variable by setting global $post in your function.

    So I’m wondering if perhaps it would make more sense for you to attach your determine_thing function to a standard WP action such as wp or wp_head.

    Your function doesn’t need to return anything either if you take this approach, as you’ve already set the $thingType variable to global as well.

    I hope this gives you some ideas. Be sure and let us know what solves your problem!


Viewing 1 replies (of 1 total)
  • The topic ‘Quick Theme / Function question’ is closed to new replies.