0

I have a view that it has an contextual filter based on "uid". Now I need to get it via PHP and I can use views_embed_view(). But I need to get only page FOO or page BAR and views_embed_view() accepts only "arguments/contextual filter".

Which is the correct way to call views FOO, for display BAR, using argument "uid = X" and get only "page = Z"

Thanks.

M.

2 Answers 2

0

You can specify a page inside a view with views_embed_view().

Fisrt argument will be the view's name

Second will be the page you want to display (Defaults to default)

And then as many contextual filters you want/have

So it will look something like this views_embed_view('view_mahcine_name', 'page_3', uid);

2
  • Page number (?page=X) is not a contextual filter.
    – ZioBudda
    Feb 23, 2015 at 22:37
  • Hmm i see what you mean now, @rjacobs looks good Feb 24, 2015 at 9:31
0

I think you have 2 options to set the pager offset programmatically:

Because views_embed_view() does not take any parameters for a pager or exposed filters directly, I think you could implement your own version of its "guts" that also internally sets the pager data manually. Here's an excerpt of how to do that from this post (disclaimer, I've not personally tested this):

$view_args = array(); // contextual filter args go here
$view_object = views_get_view($view_name);
$view_object->set_current_page($offset); // manually set page offset
$html = $view_object->preview($view_display, $view_args);

Alternatively, if really have to use views_embed_view(), then I think you'll have to modify the $_GET global variable directly before-hand, or ensure that your "page" query string is already in the URL. As far as I know views typically extracts the pager offset directly from $_GET['page']. The trick here is that it's not necessarily guaranteed that view's internal build/execute methods didn't manually overrride the pager data in some way, and you would have to be sure you don't have any conflicts with other pagers on the same page. It's also never great to be manipulating globals directly. Anyway, for most vanilla views, setting $_GET['page'] before calling views_embed_view() would likely work, but the first solution is still probably preferred.

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.