I am trying to:
Create a CRED form with a select-field that shows all related parents which have the same author of the post (not the parent posts of different authors).
I tried:
- JSON view inside a generic field -> returned blank (A)
- custom <option> generation via view filtered by author -> didn't save (B)
- Reading/trying all forum posts and documentation related to this problem without any good result
I expected to see:
A simple way to solve this: "show select box in cred form with parent posts that have same author"
Instead, I got:
Many hours of wasted time trying to make it work without result.
So, what I first did (A) and didn't work:
# A view "parentposts-for-author-in-json" with a filter on author:
"Select posts with the author the same as the current logged in user."
... and has this loop code:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title output='sanitize']"}
[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title output='sanitize']"}
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[/wpv-no-items-found]
[wpv-layout-end]
This view template returns something like this if I call it plainly (by placing [wpv-view name="parentposts-for-author-in-json"] inside a page for example):
{"value":"200","label":"Parent test 1"} ,{"value":"67","label":"Parent test 2"}
However this generic form code never generates a visible select field:
[cred_generic_field field='_wpcf_belongs_parentpost_id' type='select' class='' urlparam='']
{
"required":1,
"validate_format":0,
"persist":1,
"default":[],
"options":[ [wpv-view name="parentposts-for-author-in-json"] ]
}
[/cred_generic_field]
After that I tried an ALTERNATIVE SOLUTION (B) also without excepted result:
In CRED form:
<select name="_wpcf_belongs_parentpost_id">
[wpv-view name="parentposts-for-author"]
</select>
In view "parentposts-for-author":
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<option value="[wpv-post-id]">[wpv-post-title]</option>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[/wpv-no-items-found]
[wpv-layout-end]
This showed the correct options in the CRED form but never persists to the database.
My questions:
- Why is B not working? The alternative feels more light/elegant then the JSON-way.
- If B is not possible, how can I make A work?
Thanks in advance for a quick reply!