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 8827149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:18:30+00:00 2026-06-14T07:18:30+00:00

This code works fine. I am able to get a page of populated JSON

  • 0

This code works fine. I am able to get a page of populated JSON that is written to a cache file:

$test_tag = "afro";

$page = 1;
$images = array();
$tags = array();
$imagetype = 'Recent Cuts';
$per_page = 60;
$orderby_view = FALSE;

$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));

BUT when I enclose this code in a function, the JSON response is written to file as before, but it is just an empty skeleton with no data. All I am doing is enclosing the above code inside a new function, passing in the top $test_tag variable and executing the function. I also add an echo() which verifies that $test_tag is passed in. For some reason, it appears that the get_pix() and/or get_option() functions are failing to get the data even though $test_tag is the same in both tests.

$test_tag = "afro";
newFunction($test_tag);

function newFunction($test_tag) {

$page = 1;
$images = array();
$tags = array();
$imagetype = 'Recent Cuts';
$per_page = 60;
$orderby_view = FALSE;


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

$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));
}

I really hope I am missing something simple. I can only suspect that inside newFunction(), $test_tag is somehow treated differently even though echo() proves it has the same value.

  • 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-14T07:18:31+00:00Added an answer on June 14, 2026 at 7:18 am

    I figured it out. The wordpress function get_the_ID() would not work inside of the function, returning a null value. Instead I used $post->ID, which is identical, and it worked. I don’t like WordPress.

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

Sidebar

Related Questions

web page : http://sideradesign.com/eco-art/gallery/ This code works fine in all brwosers except IE8 (haven't
This code works fine in Chrome. However, in Firefox, when it hits the GMxhr
This code works fine, but I'll want to handle exception if any thing goes
this code works fine until I start scrolling: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
This code works fine to find an available room within certain date, but it
This code works fine in C#: Expression.Lambda(LambdaBody); But none of the methods for building
The code below is creating a server to communicate with clients.This code works fine
I'm using core motion in my app. This code works fine: motionManager = [[CMMotionManager
Please i need help, this code below works fine on my localhost, php5.3+ but
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =

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.