I am using custom fields (with the free version of ACF) to add additional, sometimes required, formatted content to the respective custom post type entries. I put together a little site-specific plugin which includes filters to add the custom fields to excerpt and content and puts them out, via a loop, as a list of:
{CUSTOM FIELD LABEL}: {CUSTOM FIELD VALUE}
The website should be available in English and German. Using the Sublanguage plugin, I could translate most of the website, but not the custom field labels.
From what I read on i18n/l10n and Wordpress, I understood that I should best use __() for the labels when creating the custom fields. Since custom field creation is realized by ACF plugin code, I assume I have to create the fields "myself" so that I can do multilingual labels using __(). I guess, I would then realize the actual translation of the fields with Loco Translate.
ACF offers a neat way to export my already existing ACF-created field groups, which provides me with the PHP code to create the fields "on my own". I put the ACF code inside a new function in my site-specific plugin and hooked it to the acf/init action. I did pretty much the same as described in this question, but nothing happens: When I trash the custom field groups within the ACF interface afterwards, no custom fields appear in the "new post" screen.
So basically, I am having one question that, depending on the answer, will spawn follow-up questions:
Is this how I should and can realize bi/multilingual custom field labels?
If no: How else would you implement bilingual custom field labels/names?
If yes: Am I hooking the function to the wrong action?
PS: I wasn't sure if this belongs here or in the WP StackExchange, since part of it is coding related and part of translation-logic-related. Please tell me if I should move it over to the other platform.
Alright,
I was able to solve most of this myself in the meantime:
I did not hook into the correct action. As it turns out, acf/init is only available in ACFv5 (pro), while the free edition is still in version 4.x. I hooked into init - et voilà: there are my field groups.
Using __() functions to declare my custom fields' labels, Loco Translate made it quite easy to translate the strings myself.
Conclusion
Apparently, my assumptions were correct - this is how to create internationalized custom field labels :) Nevertheless, I wasn't able to effectively translate the options of a checkbox field I am using, although Loco recognized the string and I provided a translation.
However....
The solution is far from perfect:
I am now using two plugins to translate as much as possible on the website.
Creating the ACF field groups "myself" through PHP code in my site-specific plugin, I needed to remove them from the admin UI. This means, that it's going to be difficult for any standard users to change anything about them in the future (which might of course be a feature as well :))
Related
Elementor is great to link single ACF-field content.
But I need to combine some of them in the ACF Layout "group", so that it's easier for the customer to overview and edit the content.
But Elementor does not support ACF fields inside an ACF group – they simply don't show up in the Key-dropdown.
Is there a way to get that going?
According to document Elementor Integration With ACF on Elementor official website, complex custom field types such as group, repeater haven't been supported yet.
But there is a way to get value from ACF group field, see here(wordpress support thread). While I haven't tested it.
I know you may want to sort those fileds by categories or other taxonomies to get a better logic and cleaner interface. But this would also limit you to certain widget in 3rd party plugins. Built-in dynamic content is really handy, I don't think it's worthy to give it up by using ACF group field.
So I suggest you to use regular field types along with conditional logic(each of), it's a better choice at this moment though the interface would be messy.
I've create some custom posts on my customized theme in wordpress, in which the polylang plugin is activated.
The translation works well, but the problem is that I need that specified contents remain the same between translated posts. With the normal posts you can deactivate the translation for the media type, but this will not apply for custom content type.
For example, if I got two languages, like English and Spanish, and I create a new custom english post:
[ENG POST]
TITLE
content1 *
content2
media1 *
media2
I'd want that on the spanish post some of the contents to be already populated with some of the contents that I've already written\uploaded in the english post (the ones with the "*" ), like:
[SP POST]
-empty-
content1
-empty-
media1
-empty-
For the custom posts I'm using the CMB2 plugin.
Is there an elegant way to do this?
Never done anything like that, but to my knowledge polylang creates another post and, when loading the new language form, completely reloads CMB2 fields, triggering all related events.
Getting in the right event and finding the original post id should allow you to set the previous values as default for the corresponding fields, but it's just theory, since I never really tried. Let me know if it works.
If you use CMB2's custom fields to create those parts of the custom post type content, here is the more or less elegant, straightforward way to achieve the goal.
Create the wpml-config.xml file (it's pretty self-explanatory)
<wpml-config>
<custom-fields>
<custom-field action="copy">cf_content_to_populate</custom-field>
<custom-field action="copy">cf_media_to_populate</custom-field>
<custom-field action="translate">cf_content_to_translate</custom-field>
<custom-field action="translate">cf_media_to_translate</custom-field>
</custom-fields>
</wpml-config>
and save it to the root directory of the theme you use.
cf_content_to_populate and cf_media_to_populate will be available all over the languages without translation, but cf_content_to_translate and cf_media_to_translate will require translation.
Using wpml-config.xml you can manage copying and/or translation of
specified custom fields;
specified custom post types;
specified taxonomies;
specified admin texts as custom plugin or custom theme options etc..
But you can't do this on per-post basis out-of-the-box.
Official Polylang documentation on The wpml-config.xml file.
I have a custom post type. Pages of this custom post type are displayed via a special template. in this template i use previous_post_link() and next_post_link() to create links to previous/next posts of this custom post type.
Since I currently only want to show a few of these custom-post-type pages to my users, I created a custom field called release with a boolean true/false value to indicate if these posts should be shown.
Obviously, the previous/next_post_link() functions should also be aware of that. However, they are not currently. That means they also link to pages where the custom field released is set to false. How can I tell these functions to only use pages where a custom field (released) has a specific value (true).
Update: I know that the solution is to apply some filters to the default functions and to somehow adapt the SQL query which is used to retrieve previous/next posts. However I do not know how to put together the puzzle pieces (where/how to apply the filters and how to adapt the SQL)
This may be related to this question, however I dont really know what to do: https://wordpress.stackexchange.com/questions/8823/how-to-order-adjacent-posts-prev-next-by-custom-field-value
This seems also to be related: https://wordpress.stackexchange.com/questions/96670/custom-post-type-navigation-on-custom-field
couldn't get it to work even though I know how it SHOULD work: addFilter() for get_{$adjacent}_post_join and get_{$adjacent}_post_where with custom SQL query code..
However, this plugin did the trick for me: http://www.ambrosite.com/plugins/next-previous-post-link-plus-for-wordpress
I used the in_same_meta key.
I want to add a new entity named "ideas" having different fields. I want to add this to the admin side, where a logged in user can add/edit new "idea", which can be published/unpublished to the site.
I don't want to edit via php and make things complicated, instead do it from the wp-admin log in front-end. Is there a plugin for this? I need 3-4 such entities to be created, and define fields for each such entity.
New edit:
Custom Post Type is the best option I feel. Can anyone suggest, a free plugin for form to capture the values for the custom post type?
According to this WCK - Custom Fields and Custom Post Types Creator plugin you can achieve this.
WordPress Creation Kit consists of three tools that can help you
create and maintain custom post types, custom taxonomies and most
importantly, custom fields and metaboxes for your posts, pages or
CPT's.
WCK Custom Fields Creator offers an UI for setting up custom meta
boxes with custom fields for your posts, pages or custom post types.
Uses standard custom fields to store data.
WCK Custom Post Type Creator facilitates creating custom post types by
providing an UI for most of the arguments of register_post_type()
function.
WCK Taxonomy Creator allows you to easily create and edit custom
taxonomies for WordPress without any programming knowledge. It
provides an UI for most of the arguments of register_taxonomy()
function.
Hope it helps you.
You can use a combination of two plugins to fit your needs:
The Custom Post Type UI (https://wordpress.org/plugins/custom-post-type-ui/) makes it possible to generate Custom Post Types (like "Posts" or "Pages") and Custom Taxonomies. This is how you can create your entity "ideas" which will show up in the admin menu.
With Advanced Custom Fields (https://wordpress.org/plugins/advanced-custom-fields/) you can define additional content fields for your "ideas"-posttype and others. It also can handle relations between your added custom-post-types
Using the SWIFT Templates as proposed in Touqueer Shafis answer will be sufficient when you only have smaller bits of information to display on the page or if you just want to display archives of your custom-post-types. But you will quickly reach the borders of these templates when it comes to single-pages.
I recommend altering the PHP of your template files manually: you will have more control where and when to display the contents of the custom-post-types and custom-fields you added on your page.
Well, I'm not really gonna give you the answer you want to hear but I want to give you an advice from my own experience.
Using a plugin will make things usually much more complicated than doing it manually. Consider some things:
1) The plugin may not be supported for ever (or long), so if the author decides that he or she wants to be a gardener instead of a developer you're screwed. Unless you want to wrap your head around the plugin code and proceed developing it on your own. This is especially true for "underground"-plugins which are not so popular and/or maintained by a single person. Although I think you CAN rely on the "big" players like "Advanced custom fields"
2) At some point you may find that the plugin you are using doesn't support some sort of customization that you really need and quite a few plugins are built in a way that makes it hard to extend them or break out from the way they work.
So I recommend you to wrap your head around custom taxonomies and post types and just add them with PHP in your functions.php or a custom plugin. It's very very easy (it's really just arrays with arguments). You could use this visual code generator as a starting point:
http://generatewp.com/post-type/
And for adding custom fields I recommend using Advanced custom fields. You won't need any other plugin for backend management customization and it's built in a way that you can even export your custom fields as php so if they ever drop support you still have a good starting point.
I've created new content type. And I want add new custom non-standard field. The field should consist of two text fields. Let's say: double text field. Ex.: Product content type and I want to add features of product such as: weight, length etc(many features). First field is 'Feature' and the second one is 'Value of feature'. The question is: How I can realize such a field? Module, hooks?
You can create your own field pretty easily, you'll need a custom module and to implement a bunch of hooks like you suggest.
Rather than go through all of those here you'd be better off downloading the Examples module, and looking at field_example. I've based tons of custom fields off of that code and they've all worked perfectly. Plus the module is well commented and gives you good insight in to the way the field/widget systems work.
Hope that helps
One straightforward alternative is to use the Field Collection module