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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:43:36+00:00 2026-06-14T10:43:36+00:00

I need to get a variable $option passed to the php script. the $option

  • 0

I need to get a variable $option passed to the php script. the $option is on the hidden field named “option”.

Basically the user have some items that can be rearranged by using something like drag & drop. The items are stored in an array and once the items had been rearranged, the array gets reordered and saved.

The problem can’t be solved by changing get_option($option); to get_option('myoption'); I must get $option from the hidden field.

I spend a lot of time searching on the web for an example, solution and tutorial with no hope, It’s too much for my head.

            array_walk($_POST['order'], 'strip_text_menu_editor');
            $order_array = $_POST['order'];
            $current_menu = get_option($option);    
            $new_order = array();
            foreach($order_array as $order) {
                foreach($current_menu as $key => $value) {
                    if($order == $key) {
                        $new_order[] = $value;
                    }
                }
            }
            update_option($option, $new_order);
            echo '<script type="text/javascript" >
            jQuery(document).ready(function($) {
            var i = 0';
            echo "jQuery('#sortable li').each(function(){
                    var name = 'listItem_' + i;
                    i++;
                });
            });
            </script>";
            die(true);

jQuery

            jQuery(document).ready(function(jQuery) {
                jQuery('#sortable li:odd').addClass('stripe');
                jQuery('#sortable').sortable({
                    handle : '.handle', 
                    update: function(event, ui) {
                        jQuery('#sortable li').removeClass('stripe');
                        jQuery('#sortable li:odd').addClass('stripe');
                        var order = jQuery('#sortable').sortable('toArray');
                        var data = {
                            action: 'menu_editor_special_action',
                            order: order,
                        };
                        jQuery.post(ajaxurl, data, function(response){
                            jQuery('#response').html('Got this from the server: ' + response);
                        });
                    }
                });
            });

HTML

<ul>
<li id="listItem_0" class="">Item A</li>
<li id="listItem_1" class="stripe">Item B</li>
<li id="listItem_2" class="">Item C</li>
<li id="listItem_3" class="stripe">Item D</li>
<li id="listItem_4" class="">Item E</li>
<li id="listItem_5" class="stripe">Item F</li>
</ul>

Called on the PHP script

function strip_text_menu_editor(&$value, $key) {
        $value = str_replace('listItem_', '', $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-14T10:43:38+00:00Added an answer on June 14, 2026 at 10:43 am

    From what I can see of the jQuery fragment you’ve posted, you would need to add the ‘option’ value to the data array in your post.

    var data = {
        action: 'menu_editor_special_action',
        order: order,
        option: $('input[name=option]').val(),  //This part is new
    };
    jQuery.post(ajaxurl, data, function(response){
        jQuery('#response').html('Got this from the server: ' + response);
    });
    

    Of course I don’t know what sort of data you have stored in ‘option’ and I don’t know what your get_option() etc. functions are doing with it to know how you need to send it for your server-side code to understand, but this should get you started.

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

Sidebar

Related Questions

I have a PHP-variable called $go_Adress which contains the adress I need to get
I have one variable whose content I need to get from a remote server,
I need get all items these have no categories int? categoryId = null; var
I need to get the value of a variable which is present in another
I need to get UserCarId(int) from this query and assign to int type variable.
I need to make this data variable global: $.ajax({ url: get_data.php, cache: false, dataType:
For a check i need yesterday's date at 10:00pm in a variable. I get
I need to get information on variables and the only thing I have is
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I have in my php $sel = <option> one </option> <option> two </option> <option>

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.