Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:16:19+00:00 2026-06-14T08:16:19+00:00

When I do this: {some code} previouslyDeclaredFunction($variable); {some code} I can get previouslyDeclaredFunction() to

  • 0

When I do this:

{some code}
previouslyDeclaredFunction($variable);
{some code}

I can get previouslyDeclaredFunction() to work just fine.

But when I put it inside a new function:

function newFunction($variable){

echo $variable; //see if var passes in properly
{some code}
previouslyDeclaredFunction($variable);
{some code}

}

..then call:

newFunction($variable);

..all of a sudden it stops working EVEN THOUGH I am able to echo() the $variable from within newFunction() just fine, meaning newFunction() was called properly and $variable was passed in properly. Apparently, some stuff inside just won’t work unless I remove the whole outer function. PreviouslyDeclaredFunction() is included in the php script and it does get called from within newFunction() but somehow treats $variable differently even though the echo() proves it is being passed in and is the exact same value it was before.

EDIT (ok here comes the REAL code):

$test_tag = "afro";
cacheBuilder($test_tag); //declaration of function

function cacheBuilder($test_tag) {

$images = array();
$tags = array();
$imagetype = 'Hair';
$per_page = 60;
$orderby_view = FALSE;

echo $test_tag; //this works so var is passed in fine


    $tags2 = $test_tag;
    $tags = explode(',', $test_tag);
    if( count($tags) == 1 && strlen($tags[0]) == 0 ) $tags = array();
    $tag_url = urlencode($tags2);

$cachename = dirname( __FILE__ ) . '/cache-fp/' . $imagetype . '-' . $per_page . '-' . $page . '-' . ($orderby_view ? 'by_view' : 'by_date') . $tag_url . '.json';

    $detailurl = get_option('image_detail_url');
    $detailurl .= (strstr($detailurl, '?') === FALSE ? '?' : '&');
    $json = array();
    $images = array();
    $posts = get_pix($imagetype, array('per_page' => $per_page, 'page' => $page, 'tags' => $tags), $orderby_view);


    foreach( $posts['attachments'] as $ii => $post ) {
        $ta = array();
        $meta = array();
        $imagesrclight2 = array();
        // BWP - Theater mode
        $ta['detail_url'] = $detailurl . 'uid=' . $post->post_author . '&img_id=' . $post->ID . '&theater';


        $meta = get_post_meta(get_the_ID(), 'image_tag', false);
        $ta['image_tags'] = implode(' ', $meta);


        $ta['attachment_image'] = wp_get_attachment_image($image->ID, 'thumbnail'); 
        $imagesrclight2 = wp_get_attachment_image_src($image->ID, array(150, 150)); 
        $ta['attachment_image_src'] = rawurlencode($imagesrclight2[0]);


        $images[] = $ta;
    }

    file_put_contents($cachename, json_encode($images));

}

This is a bit complicated, and it’s WordPress, so I hope this isn’t totally confusing. While there are no errors, it looks like get_option and/or get_pix are failing inside the outer function. The json produced has no data in it. When I get rid of the outer function, I get json which is populated with data as it should.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:16:21+00:00Added an answer on June 14, 2026 at 8:16 am

    I figured it out. For whatever reason, certain WordPress functions like get_the_ID() fail when I put them inside the function. Not sure why, but when I get the post ID via other means aside from the WP function, the value comes in instead of being null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is some code i made up following a course: $(document).ready(function(){ $.ajax({ type: 'GET',
I just found this in some code and I can't find anything on the
This is some code to create a basic java window: JPanel pane = new
I'm using this statement //some code int a[][]=new int[5000000][5000000]; //some code and running it
I am new to CSharp.I have seen this() in some code.My question is Suppose
Saw this in some code but didn't make sense to me, So I was
I just came across this in some code, and I'm rather confused. timer =
there. I'm using C# .wpf, and I get this some code from C# source,
This is some code i'm using in Java for Making Asynchronous function calls in
This is some code to unblock any website from listview, but now I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.