I have 2 keys:
- content
- media
I then run this:
$fields = get_post_meta($postId);
unset($fields['_edit_lock'], $fields['_edit_last'], $fields['_thumbnail_id']);
echo '<ul>';
foreach($fields as $i) {
foreach($i as $key => $value) {
echo '<li>'.$i.'->'.$value.'</li>';
}
}
That gives me:
- Array-> 327
- Array-> Custom test 1
- Array-> Custom test 2
What I'm looking for is:
- Media-> 327
- Content-> Custom test 1
- Content-> Custom test 2
Like this:
foreach ((array) get_post_meta($postId) as $arrayKey => $arrayValue) {
if (!in_array($arrayKey, array("_edit_lock", "_edit_last", "_thumbnail_id"))) {
foreach ($arrayValue as $key => $value) {
echo '<li>' . $arrayKey . '->' . $value . '</li>';
}
}
}
If you are in a scenario like this:
You have a array like this:
$fields = array(
'media' => array(
0 => '327',
),
'content' => array(
0 => 'Custom test 1',
1 => 'Custom test 2',
),
'link' => array(
0 => 'Custom test 10',
1 => 'Custom test 20',
2 => 'Custom test 30',
3 => 'Custom test 40',
),
'embed' => array(
0 => 'Custom test 100',
1 => 'Custom test 200',
2 => 'Custom test 300',
),
'_edit_lock' => array(
0 => '1667908749:1',
),
);
You just want these keys:
media
content
LInk
Embed
I need to output their values in sequence as per this example:
media
content
link
embed
New rows....
media
content
link
embed
You want to get something like this:
media->327
content->Custom test 1
link->Custom test 10
embed->Custom test 100
media->327
content->Custom test 1
link->Custom test 10
embed->Custom test 200
media->327
content->Custom test 1
link->Custom test 10
embed->Custom test 300
media->327
content->Custom test 1
link->Custom test 20
embed->Custom test 100
media->327
content->Custom test 1
link->Custom test 20
embed->Custom test 200
media->327
content->Custom test 1
link->Custom test 20
embed->Custom test 300
media->327
content->Custom test 1
link->Custom test 30
embed->Custom test 100
media->327
content->Custom test 1
link->Custom test 30
embed->Custom test 200
media->327
content->Custom test 1
link->Custom test 30
embed->Custom test 300
media->327
content->Custom test 1
link->Custom test 40
embed->Custom test 100
media->327
content->Custom test 1
link->Custom test 40
embed->Custom test 200
media->327
content->Custom test 1
link->Custom test 40
embed->Custom test 300
media->327
content->Custom test 2
link->Custom test 10
embed->Custom test 100
media->327
content->Custom test 2
link->Custom test 10
embed->Custom test 200
media->327
content->Custom test 2
link->Custom test 10
embed->Custom test 300
media->327
content->Custom test 2
link->Custom test 20
embed->Custom test 100
media->327
content->Custom test 2
link->Custom test 20
embed->Custom test 200
media->327
content->Custom test 2
link->Custom test 20
embed->Custom test 300
media->327
content->Custom test 2
link->Custom test 30
embed->Custom test 100
media->327
content->Custom test 2
link->Custom test 30
embed->Custom test 200
media->327
content->Custom test 2
link->Custom test 30
embed->Custom test 300
media->327
content->Custom test 2
link->Custom test 40
embed->Custom test 100
media->327
content->Custom test 2
link->Custom test 40
embed->Custom test 200
media->327
content->Custom test 2
link->Custom test 40
embed->Custom test 300
So do this:
echo '<ul>';
for ($i = 0; $i < count($fields['media']); $i++) {
for ($j = 0; $j < count($fields['content']); $j++) {
for ($k = 0; $k < count($fields['link']); $k++) {
for ($z = 0; $z < count($fields['embed']); $z++) {
echo '<li>media->' . $fields['media'][$i] . '</li>';
echo '<li>content->' . $fields['content'][$j] . '</li>';
echo '<li>link->' . $fields['link'][$k] . '</li>';
echo '<li>embed->' . $fields['embed'][$z] . '</li>';
}
}
}
}
echo '</ul>';
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.