How to store an ARRAY in a Wordpress Custom Field?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
My array $location is empty. But this is very strange. The list ($adresse, $lat, $long) creates the variables $lat and $long. I know that, because they are entered in the update_post_meta fields. But the array does not work.
What am I doing wrong in creating the array? Does the list only work once?
Cheers,
Denis
PHP 7.2, Wordpress 5.02, WP User Frontend Pro Plugin WPUF 3.0.2
I tried the array like $location[...] but this does not work.
I tried to make the ARRAY static like
$location = array(
'latitude' => 'lat',
'longitude' => 'long'
);
but that does not work :-(
This is my function code for Wordpress:
function update_GEOmyWP( $post_id ) {
if ( ! $post_id ) {
return;
}
if ( ! function_exists( 'gmw_update_post_location' ) ) {
return;
}
if ( isset( $_POST['aufnahmeort'] ) ) {
list( $adresse, $lat, $long ) = explode( '||', $_POST['aufnahmeort'] );
$location = array(
'latitude' => $lat,
'longitude' => $long
);
if ( $adresse ) {
update_post_meta( $post_id, 'newADDRESS', $adresse );
}
if ( $lat ) {
update_post_meta( $post_id, 'newLAT', $lat );
}
if ( $long ) {
update_post_meta( $post_id, 'newLONG', $long );
}
// I added this line to check if something is written in the meta field, but the field is empty.
if ( $location ) {
update_post_meta( $post_id, 'newLOCATION', $location );
}
gmw_update_post_location( $post_id, $location );
}
}
add_action( 'wpuf_add_post_after_insert', 'update_GEOmyWP' );
add_action( 'wpuf_edit_post_after_update', 'update_GEOmyWP' );
I would like to have an ARRAY of latitude and longitude.
I have an update:
I just loked into the database of wordpress in the postmeta table and under newLOCATION there is this THE ARRAY a:2:{s:8:"latitude";s:12:" 50.7936389 ";s:9:"longitude";s:18:" 6.952259499999968";} but why is it not in the metafield?
php arrays wordpress list
|
show 3 more comments
My array $location is empty. But this is very strange. The list ($adresse, $lat, $long) creates the variables $lat and $long. I know that, because they are entered in the update_post_meta fields. But the array does not work.
What am I doing wrong in creating the array? Does the list only work once?
Cheers,
Denis
PHP 7.2, Wordpress 5.02, WP User Frontend Pro Plugin WPUF 3.0.2
I tried the array like $location[...] but this does not work.
I tried to make the ARRAY static like
$location = array(
'latitude' => 'lat',
'longitude' => 'long'
);
but that does not work :-(
This is my function code for Wordpress:
function update_GEOmyWP( $post_id ) {
if ( ! $post_id ) {
return;
}
if ( ! function_exists( 'gmw_update_post_location' ) ) {
return;
}
if ( isset( $_POST['aufnahmeort'] ) ) {
list( $adresse, $lat, $long ) = explode( '||', $_POST['aufnahmeort'] );
$location = array(
'latitude' => $lat,
'longitude' => $long
);
if ( $adresse ) {
update_post_meta( $post_id, 'newADDRESS', $adresse );
}
if ( $lat ) {
update_post_meta( $post_id, 'newLAT', $lat );
}
if ( $long ) {
update_post_meta( $post_id, 'newLONG', $long );
}
// I added this line to check if something is written in the meta field, but the field is empty.
if ( $location ) {
update_post_meta( $post_id, 'newLOCATION', $location );
}
gmw_update_post_location( $post_id, $location );
}
}
add_action( 'wpuf_add_post_after_insert', 'update_GEOmyWP' );
add_action( 'wpuf_edit_post_after_update', 'update_GEOmyWP' );
I would like to have an ARRAY of latitude and longitude.
I have an update:
I just loked into the database of wordpress in the postmeta table and under newLOCATION there is this THE ARRAY a:2:{s:8:"latitude";s:12:" 50.7936389 ";s:9:"longitude";s:18:" 6.952259499999968";} but why is it not in the metafield?
php arrays wordpress list
1
What doesn't work? What do you mean by it?
– Jeto
Jan 4 at 13:26
try to change $location array variable name with different one.
– dipmala
Jan 4 at 13:27
$location it is empty. There is nothing in the ARRAY.
– DenisCGN
Jan 4 at 13:28
What is the value of this ?explode( '||', $_POST['aufnahmeort'] );probably gives you array with one element
– Prabowo Murti
Jan 4 at 13:31
@dipmala Changing the name does not effect anything.
– DenisCGN
Jan 4 at 13:34
|
show 3 more comments
My array $location is empty. But this is very strange. The list ($adresse, $lat, $long) creates the variables $lat and $long. I know that, because they are entered in the update_post_meta fields. But the array does not work.
What am I doing wrong in creating the array? Does the list only work once?
Cheers,
Denis
PHP 7.2, Wordpress 5.02, WP User Frontend Pro Plugin WPUF 3.0.2
I tried the array like $location[...] but this does not work.
I tried to make the ARRAY static like
$location = array(
'latitude' => 'lat',
'longitude' => 'long'
);
but that does not work :-(
This is my function code for Wordpress:
function update_GEOmyWP( $post_id ) {
if ( ! $post_id ) {
return;
}
if ( ! function_exists( 'gmw_update_post_location' ) ) {
return;
}
if ( isset( $_POST['aufnahmeort'] ) ) {
list( $adresse, $lat, $long ) = explode( '||', $_POST['aufnahmeort'] );
$location = array(
'latitude' => $lat,
'longitude' => $long
);
if ( $adresse ) {
update_post_meta( $post_id, 'newADDRESS', $adresse );
}
if ( $lat ) {
update_post_meta( $post_id, 'newLAT', $lat );
}
if ( $long ) {
update_post_meta( $post_id, 'newLONG', $long );
}
// I added this line to check if something is written in the meta field, but the field is empty.
if ( $location ) {
update_post_meta( $post_id, 'newLOCATION', $location );
}
gmw_update_post_location( $post_id, $location );
}
}
add_action( 'wpuf_add_post_after_insert', 'update_GEOmyWP' );
add_action( 'wpuf_edit_post_after_update', 'update_GEOmyWP' );
I would like to have an ARRAY of latitude and longitude.
I have an update:
I just loked into the database of wordpress in the postmeta table and under newLOCATION there is this THE ARRAY a:2:{s:8:"latitude";s:12:" 50.7936389 ";s:9:"longitude";s:18:" 6.952259499999968";} but why is it not in the metafield?
php arrays wordpress list
My array $location is empty. But this is very strange. The list ($adresse, $lat, $long) creates the variables $lat and $long. I know that, because they are entered in the update_post_meta fields. But the array does not work.
What am I doing wrong in creating the array? Does the list only work once?
Cheers,
Denis
PHP 7.2, Wordpress 5.02, WP User Frontend Pro Plugin WPUF 3.0.2
I tried the array like $location[...] but this does not work.
I tried to make the ARRAY static like
$location = array(
'latitude' => 'lat',
'longitude' => 'long'
);
but that does not work :-(
This is my function code for Wordpress:
function update_GEOmyWP( $post_id ) {
if ( ! $post_id ) {
return;
}
if ( ! function_exists( 'gmw_update_post_location' ) ) {
return;
}
if ( isset( $_POST['aufnahmeort'] ) ) {
list( $adresse, $lat, $long ) = explode( '||', $_POST['aufnahmeort'] );
$location = array(
'latitude' => $lat,
'longitude' => $long
);
if ( $adresse ) {
update_post_meta( $post_id, 'newADDRESS', $adresse );
}
if ( $lat ) {
update_post_meta( $post_id, 'newLAT', $lat );
}
if ( $long ) {
update_post_meta( $post_id, 'newLONG', $long );
}
// I added this line to check if something is written in the meta field, but the field is empty.
if ( $location ) {
update_post_meta( $post_id, 'newLOCATION', $location );
}
gmw_update_post_location( $post_id, $location );
}
}
add_action( 'wpuf_add_post_after_insert', 'update_GEOmyWP' );
add_action( 'wpuf_edit_post_after_update', 'update_GEOmyWP' );
I would like to have an ARRAY of latitude and longitude.
I have an update:
I just loked into the database of wordpress in the postmeta table and under newLOCATION there is this THE ARRAY a:2:{s:8:"latitude";s:12:" 50.7936389 ";s:9:"longitude";s:18:" 6.952259499999968";} but why is it not in the metafield?
php arrays wordpress list
php arrays wordpress list
edited Jan 4 at 14:31
DenisCGN
asked Jan 4 at 13:24
DenisCGNDenisCGN
1221315
1221315
1
What doesn't work? What do you mean by it?
– Jeto
Jan 4 at 13:26
try to change $location array variable name with different one.
– dipmala
Jan 4 at 13:27
$location it is empty. There is nothing in the ARRAY.
– DenisCGN
Jan 4 at 13:28
What is the value of this ?explode( '||', $_POST['aufnahmeort'] );probably gives you array with one element
– Prabowo Murti
Jan 4 at 13:31
@dipmala Changing the name does not effect anything.
– DenisCGN
Jan 4 at 13:34
|
show 3 more comments
1
What doesn't work? What do you mean by it?
– Jeto
Jan 4 at 13:26
try to change $location array variable name with different one.
– dipmala
Jan 4 at 13:27
$location it is empty. There is nothing in the ARRAY.
– DenisCGN
Jan 4 at 13:28
What is the value of this ?explode( '||', $_POST['aufnahmeort'] );probably gives you array with one element
– Prabowo Murti
Jan 4 at 13:31
@dipmala Changing the name does not effect anything.
– DenisCGN
Jan 4 at 13:34
1
1
What doesn't work? What do you mean by it?
– Jeto
Jan 4 at 13:26
What doesn't work? What do you mean by it?
– Jeto
Jan 4 at 13:26
try to change $location array variable name with different one.
– dipmala
Jan 4 at 13:27
try to change $location array variable name with different one.
– dipmala
Jan 4 at 13:27
$location it is empty. There is nothing in the ARRAY.
– DenisCGN
Jan 4 at 13:28
$location it is empty. There is nothing in the ARRAY.
– DenisCGN
Jan 4 at 13:28
What is the value of this ?
explode( '||', $_POST['aufnahmeort'] ); probably gives you array with one element– Prabowo Murti
Jan 4 at 13:31
What is the value of this ?
explode( '||', $_POST['aufnahmeort'] ); probably gives you array with one element– Prabowo Murti
Jan 4 at 13:31
@dipmala Changing the name does not effect anything.
– DenisCGN
Jan 4 at 13:34
@dipmala Changing the name does not effect anything.
– DenisCGN
Jan 4 at 13:34
|
show 3 more comments
1 Answer
1
active
oldest
votes
why is it not in the metafield
Did you mean that it's not shown in the custom field?
Your code above only does the job of saving the array value to the database. And as you already verified that value in the database (in the form of serialized array), it seems to work correctly.
Please check the code you use to display the custom field and see how you get the data from the database and show in the field. It's where you should debug.
Hello, yes, it is fine in the database.And it works fine now, I was irritaded by the custom field thing. Thanks.
– DenisCGN
Jan 19 at 12:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54039802%2fhow-to-store-an-array-in-a-wordpress-custom-field%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
why is it not in the metafield
Did you mean that it's not shown in the custom field?
Your code above only does the job of saving the array value to the database. And as you already verified that value in the database (in the form of serialized array), it seems to work correctly.
Please check the code you use to display the custom field and see how you get the data from the database and show in the field. It's where you should debug.
Hello, yes, it is fine in the database.And it works fine now, I was irritaded by the custom field thing. Thanks.
– DenisCGN
Jan 19 at 12:15
add a comment |
why is it not in the metafield
Did you mean that it's not shown in the custom field?
Your code above only does the job of saving the array value to the database. And as you already verified that value in the database (in the form of serialized array), it seems to work correctly.
Please check the code you use to display the custom field and see how you get the data from the database and show in the field. It's where you should debug.
Hello, yes, it is fine in the database.And it works fine now, I was irritaded by the custom field thing. Thanks.
– DenisCGN
Jan 19 at 12:15
add a comment |
why is it not in the metafield
Did you mean that it's not shown in the custom field?
Your code above only does the job of saving the array value to the database. And as you already verified that value in the database (in the form of serialized array), it seems to work correctly.
Please check the code you use to display the custom field and see how you get the data from the database and show in the field. It's where you should debug.
why is it not in the metafield
Did you mean that it's not shown in the custom field?
Your code above only does the job of saving the array value to the database. And as you already verified that value in the database (in the form of serialized array), it seems to work correctly.
Please check the code you use to display the custom field and see how you get the data from the database and show in the field. It's where you should debug.
answered Jan 5 at 17:31
Anh TranAnh Tran
209210
209210
Hello, yes, it is fine in the database.And it works fine now, I was irritaded by the custom field thing. Thanks.
– DenisCGN
Jan 19 at 12:15
add a comment |
Hello, yes, it is fine in the database.And it works fine now, I was irritaded by the custom field thing. Thanks.
– DenisCGN
Jan 19 at 12:15
Hello, yes, it is fine in the database.And it works fine now, I was irritaded by the custom field thing. Thanks.
– DenisCGN
Jan 19 at 12:15
Hello, yes, it is fine in the database.And it works fine now, I was irritaded by the custom field thing. Thanks.
– DenisCGN
Jan 19 at 12:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54039802%2fhow-to-store-an-array-in-a-wordpress-custom-field%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What doesn't work? What do you mean by it?
– Jeto
Jan 4 at 13:26
try to change $location array variable name with different one.
– dipmala
Jan 4 at 13:27
$location it is empty. There is nothing in the ARRAY.
– DenisCGN
Jan 4 at 13:28
What is the value of this ?
explode( '||', $_POST['aufnahmeort'] );probably gives you array with one element– Prabowo Murti
Jan 4 at 13:31
@dipmala Changing the name does not effect anything.
– DenisCGN
Jan 4 at 13:34