Problem:
A View uses a Content Template styled with Divi for its output. There is custom CSS added to the Divi modules, but the styling breaks on the front end when new posts are added.
Problem: How can I use decimal values in a numeric field, and how can I convert between displaying fractions and decimals?
Solution:
There is not a simple answer here. One option is to create a select field with each fraction listed in text, and its value predefined as a decimal. For example, the options could be as follows:
Text: 1/2, Value: 0.5
Text: 1/3, Value: 0.333333
Text: 1/4, Value: 0.25
Text: 1/8, Value 0.125
Text: 2/3, Value: 0.666666
Text: 3/4, Value: 0.75
Text: 3/8, Value: 0.375
Text: 5/8, Value: 0.625
Text: 7/8, Value: 0.875
I am moving a site over from using CMB2 to take advantage of the upcoming relationships API.
It contains repeating fields but using CMB2, they are just stored as a serialized array in post meta.
From reading the documentation, it seems Toolset stores them within a hidden CPT, and all I can see is tutorials for accessing them by using a View/GUI.
I wasn't intending to use Views for this project. Do you have documentation for how to access them with API Functions?
Solution:
There isn't exact document for the Repeating Fields Groups API, but it is using child post type to store the Repeating Fields Groups , so you can use function toolset_get_related_posts() to get the child posts, then display custom field of each child post, for example:
1) Create a Repeating Fields Groups "my-fields-group" in post type "my-cpt", add some custom field into the field group
2) In the your theme file single.php, add below codes:
$child_posts = toolset_get_related_posts(
get_the_ID(), //Post to query by.
'my-fields-group', //Slug of the relationship to query by
'parent', //Name of the element role to query by.
100, //Maximum number of returned results
0, //Result offset
array(),//Additional query arguments
'post_id', //Determines return type
'child' // which posts from the relationship should be returned
);
var_dump($child_posts);
As you can see the last parameter is "child", it will be able to query the child posts of current post.
Problem:
On small screens the date picker UI is partly obscured on the client's site by the header, which is rendered on top of the date picker.
Solution:
The theme in question sets a very high z-index for its header.
The solution is either to set a more sensible z-index for the header, or increase the z-index of the date picker to a higher level, with the following:
Problem:
How to conditionally display one field based on another field when using the new repeating field groups available in the Types and Views betas?
Solution:
You can't, that functionality is missing from the betas but will be fixed by the stable production releases.
I want to show default values for my fields, in case the field is not edited when saving the post (is empty).
I am editing and creating posts with CRED.
Solution
There are 2 possible ways to achieve this, one while adding the value of the Field, the other when displaying the field on the front end.
1. While adding the field value (edit the field on the front end thru a CRED form)
- create the custom fields and include them in the CRED Form
- pass a default value to them by using the "value" attribute
==> Since you had set a default value, the field will always show that default value if not changed
==> You can achieve the same by setting the default value in Toolset > Post Fields directly
Or, you can skip the above steps and update the Custom Field (if empty) with a custom hook to
update_post_meta()
with your default value, using the
cred_save_data()
filter
2. When outputting the field value on a post
- create the custom fields and include them in the CRED Form
- submit the cred form with eventually empty optional fields
- display the fields as used to, but wrap them in an HTML conditional
In the conditional, check if the field is empty to display your custom default text, or if it's not empty you can display the value of the field.
This customer had created a custom hook to auto assign some numbers to a custom field, however he wanted to prefix the numbers when they are being saved.
Solution:
To add a prefix when manually updating custom field take a look at the example below.