0

I have an array that is called within a wordpress loop. I also need to call the same array on the same page outside of the loop.

The second array always returns blank, and that happens even if I use copy the array and add it outside of the loop where I'm using it a second time.

I have no idea why this is happening and how to proceed.

<?php
// get ACF custom relationship field 'select'
$rmcwordwide = get_field('rights_management_control_by_worldwide', $post->ID); $rmcwordwidearray = str_split($rmcwordwide,2);   
$rmcnorthamerica = get_field('rights_management_control_by_northamerica', $post->ID); $rmcnorthamericaarray = str_split($rmcnorthamerica,2);
$rmcusaonly = get_field('rights_management_control_by_usaonly', $post->ID); $rmcusaonlyarray = str_split($rmcusaonly,2);
$rmcusalatam = get_field('rights_management_control_by_usalatam', $post->ID); $rmcusalatamarray = str_split($rmcusalatam,2);
$rmclatamonly = get_field('rights_management_control_by_latamonly', $post->ID); $rmclatamonlyarray = str_split($rmclatamonly,2);

// Merger arrays
$rmcarray = array_merge( (array)$rmcwordwidearray, (array)$rmcnorthamericaarray, (array)$rmcusaonlyarray, (array)$rmcusalatamarray, (array)$rmclatamonlyarray );
// GET USERS COUNTRY LOCATION FROM IP USING MAXMIND
require '/home/xxxx.com/public_html/vendor/autoload.php';

$gi = geoip_open("/home/xxxx.com/public_html/GeoIP.dat",GEOIP_STANDARD);
$ip = strtolower($_SERVER['REMOTE_ADDR']);
$countrycode = strtolower(geoip_country_code_by_addr($gi, $ip));
geoip_close($gi);

if (in_array($countrycode, $rmcarray)): ?>HELLO<?php endif; ?>

So there's one string in each of the arrays. I then break down the string and make a new array for each.

Then I merge the arrays.

Then I get the users location and if an entry in the merged array and the users country code match then...

6
  • 4
    Add code. No way to know what is happening based on a possibly flawed description. Commented Sep 8, 2017 at 16:21
  • Is this the answer you're looking for? Store array in while loop to use outside Commented Sep 8, 2017 at 16:28
  • We are unable to help you to find the problem if you don't show us the code that it is in... we are not mind readers! :) You need to include your relevant code as a Minimal, Complete, and Verifiable example and a summary of what you have tried already. Please review How to ask a question. Commented Sep 8, 2017 at 16:28
  • 2
    "that is called within a wordpress loop" - where is that? Commented Sep 8, 2017 at 16:47
  • 1
    You say you have problems because of the 2 loops, yet your code doesn't include any... Commented Sep 8, 2017 at 16:49

1 Answer 1

0

Create your own array var before the loop starts. Inside of the loop, add the loop result to the new array each iteration. Then use the newly populated array anywhere you want outside of the loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.