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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:46:12+00:00 2026-06-05T21:46:12+00:00

There is a loop in the function I want to modify: foreach ( $form_fields

  • 0

There is a loop in the function I want to modify:

foreach ( $form_fields as $key => $val ) {
        if ( 'menu_order' == $key ) {
            if ( $gallery )
                $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>";
            else
                $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";

            unset( $form_fields['menu_order'] );
            break;
        }
    }

This loop is looping through $form_fields array. if “menu_order” is the key, then, do something and break. Now I want to add one more key to do things as the above. So, I modified it as following:

foreach ( $form_fields as $key => $val ) {
    if ( 'menu_order' == $key ) {
        if ( $gallery )
            $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>";
        else
            $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";

        unset( $form_fields['menu_order'] );

    }

    if ( 'post_status' == $key ) {
    if ( $gallery )
        $status = "<div class='post_status'> <input class='post_status_input' type='text' id='attachments[$attachment_id][post_status]' name='attachments[$attachment_id][post_status]' value='" . esc_attr( $val['value'] ). "' /></div>";
    else
        $status = "<input type='hidden' name='attachments[$attachment_id][post_status]' value='" . esc_attr( $val['value'] ) . "' />";

    unset( $form_fields['post_status'] );
    break;
}

}

Please note that I removed the break in original code, add the break at the end of the loop. I think this should make the loop going till it finished my newly added block.
But this code doesn’t print the post_status input box as expected. Where did I go wrong in the loop?

  • 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-05T21:46:14+00:00Added an answer on June 5, 2026 at 9:46 pm

    Here’s a simple fix: Get rid of the loop. Since you know the keys, you don’t need it, just do this to access the array elements directly:

    if ( $gallery )
        $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $form_fields['menu_order']['value'] ). "' /></div>";
    else
        $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $form_fields['menu_order']['value'] ) . "' />";
    
    unset( $form_fields['menu_order']);
    

    Do the same for the 'post_status' field.

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

Sidebar

Related Questions

I want to parallelize a loop in a class member function. However there are
Inside the initialize() function there is a jQuery each loop. Inside that loop is
Is there any way to loop in NavigableMap in Java? I want to access
Is there a way to wait for hide function in a loop? I mean
Here are the inputs I want to loop through Main photo: <input type=file name=image[]
If I want to loop until a keystroke there is a quite nice Windows
I have a boring function to run, I want to loop through it to
There's a loop where we get certain data. Depending on the data, file writer
find whether there is a loop in a linked list. Do you have other
If I have a standard for loop is there a more efficient way to

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.