On my custom module, I defined the following hook_menu() function.

function motel_events_menu() {

    $items['ajax/pastevents/%'] = array(
        'title' => 'Get Past Events',
        'page callback' => '_motel_events_get_pastevents(%)',
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,

    return $items;

In this function, how can I retrieve the % argument that is passed in 'ajax/pastevents/%' so I can send it to my _motel_events_get_pastevents() function?


2 Answers 2


'page callback' => '_motel_events_get_pastevents(%)',

should be

'page callback' => '_motel_events_get_pastevents',

then insert

 'page arguments' => array(2),

immediately after. ajax is at position 0, pastevent is at position 1 and the wildcard % is at position 2. Counting for arguments starts at 0. The callback function will have a variable to pass in the wildcard value argument.

function _motel_events_get_pastevents($arg){

Some folks like to use the arg(n) form for arguments as its always present whether declared or not but I tend to use formal declarations.

  • Thank you very much for your reply, this is exactly what I've done. I didn't say I changed page callback' => '_motel_events_get_pastevents(%) to page callback' => '_motel_events_get_pastevents in my comment though.. Thanks a lot!
    – acanana
    Commented Aug 27, 2015 at 6:57

You don't need to defined % in page callback you get url parameter within your function by calling arg(2).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.