1

i want to limit node reference (autocomplete widget) based on one of CCK field on current node. So, i made view to limit results and in argument->Provide default argument->PHP Code. And write code like this:

$mynode = node_load(arg(1));
return $mynode->field_foo[0]['nid'];

But problem is in that arg(1) is not returning NID of current page but string 'autocomplete' (i guess it is name of function). (Didn't had luck with menu_get_object() either)

So how can i get NID of current node other than using ARG() in views custom PHP argument?

Can i reference directly on CCK field (yes, as I sad it is on samo page as autocomplete text-field)?

Thanks for help.

UPDATE: This is specific to autocomplete widget.

It works well with other widget types (select list, checkbox...)

  • Can you add the output of a var_dump($_GET['q']); to your question please? – berkes Aug 31 '11 at 8:44
1

If you want to have the current NID of the viewed page in your view, you should use the following:

In your view: At the Arguments section you select "Node:nid", in the configuration of this argument at "Action to take if argument is not present:" you can choose "Provide default argument" after that you choose "Node ID from URL".

And there you have your NID in your view.

| improve this answer | |
  • Tnx for reply, but i need to have NID in my function so I can access CCK field on page. – Nebojsa Aug 31 '11 at 13:29
1

Lets say if you have these fields in a node creation form. Like

  1. Select Field
  2. Auto-complete

And the auto-complete should show results based on the first field. Now you ll be using the auto-complete even before this node is created right? means the nid of the node will not be created yet.

Or is it like, the nid that you want to pass is that of the result in the 1st field ?

| improve this answer | |
  • Auto complete should be based on selection made on select field both on node create and node edit. – Nebojsa Oct 4 '11 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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