Not a presentation, but a view, of course, a typo
I am trying to setup a view. I have a fight post type. I am creating a view with this CPT. I need the following.
(see images).
The problem is that everything is fine, as long as battles with the same custom field value exist, if not, everything shifts (Issue.jpg).
That is, I need the following. Sort by fight number (custom field). And in the row should be 2 fights, even if the second fight is not created (does not exist). I tried the nested view, by the attribute of the custom field, but with no success.
I would be grateful for any help
So you would like to automatically duplicate one of the View results if it does not have a Fight in the second column, is that correct? Unfortunately there is nothing exactly like that built-in to Views. I think you could use the wpv_filter_query_post_process API to programmatically manipulate the results, or you could use custom JavaScript to duplicate results in the list after the page loads. Both of these can have an impact on pagination and post counts, so they would work best with unpaginated Views.
Here's the documentation for that API:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process
Here's an example where another User loops over the results of a query using that API:
https://toolset.com/forums/topic/ordering-a-parametric-search-view-by-taxonomy/
Let me know if you'd like to learn more about that filter.
Yes, you understand me. But I was not entirely accurate in the description of the problem. I attach updated data. I don’t want to duplicate the results, I want to reserve a place for “no results” or something like that, instead all the results are shifted by one, which is unacceptable. I also thought about a javascript solution, but a Views-level solution would be ideal. Could you guide me about that filter.
So what I need.
Checking each value of the custom field (for example, if there is a fight with number 1, show me a second fight with the same number, if there is none, show "not found")
Okay I see your images and I understand more clearly now, thanks. I'm not aware of a simple way to achieve exactly what you have described. I can show you how to use one View to display one row, filtered by custom field value using a shortcode attribute. You can use the "pad" option to easily show "No results found" in the second column if only one item exists.
The problem is how to create a View which will loop over all the rows. It is not possible to loop over custom field values. It is only possible to loop over posts, taxonomy terms, or Users. So if you used a taxonomy term instead of a custom field value, that might work. You would create a View of the taxonomy terms, and insert the View of Fights in the loop of the View of terms.
Another option is to use a separate post type, like "fight pairs", and create a many-to-many relationship with Fights. Add the custom field to the Fight Pairs post type, and create a View of Fight Pairs. Then you create a View of Fights filtered by post relationship and insert that View in the Fight Pairs View.
So if you used a taxonomy term instead of a custom field value, that might work. You would create a View of the taxonomy terms, and insert the View of Fights in the loop of the View of terms.
This is interesting, Christian, thanks for giving the thought in this direction.
This topic can be considered resolved. But I ran into another problem. The nested post view in taxonomy view is not working as expected.
Perhaps the problem appears because the id of the current page is replaced by the views id when paginating completed. I found this when I tried to display the id of the current page in the taxonomy view.
Could you look at the demo
enlace oculto
You should be able to access the ID of the current page - "New Event" - using this syntax:
[wpv-post-id item="$current_page"]
If this isn't working as expected, I will be glad to take a closer look.
Since Nigel deals with the problem on another ticket, this thread can be considered resolved.
Just leave a link here so that these topics are related.
https://toolset.com/forums/topic/ajax-pagination-taxonomy-view-with-nested-post-view-doesnt-work/
Thank you!