How to maintain specified fields invariate between linked custom posts with polylang - wordpress

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.

Related

bilingual custom field labels with ACF (free version)

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 :))

Wordpress customization on custom post

Is there any option? So I can add an option on any custom post via WordPress customization? Actually, I added a custom post on my WordPress theme. Here user needs to add font awesome icon. But I do not want to add option tree metabox and not a custom field. A user will not remember different custom field. So Is there any option?
At some level you are going to end up adding something like a custom field to your post. However, I agree that the user interface for custom fields is clunky and non-intuitive. I agree with you that making an end-user use that would be a bad idea.
Instead, I would recommend using the Advanced Custom Fields plugin. It enables you to add meta-data to posts, pages and/or custom post types. It's extremely flexible, intuitively designed and well-documented.
ACF permits you to place your custom field in a variety of places on the Add Post (or custom post) page: just below the visual editor window, on the right with the meta-boxes, or in a meta-box.
https://www.advancedcustomfields.com/

Wordpress - form to capture the values for the custom post type

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.

Add custom fields while add/edit wordpress category

I am using WP-3.5.1 and want to know how can we add more custom fields (image, radio, check-box, drop-down) while adding/editing category?
I found http://en.bainternet.info/2011/wordpress-category-extra-fields but first here author did not mention
Where to add his code?
For which version of wp this code be use?
What affect if we upgrade to latest version?
What must be pass extra_category_fields( $tag ) in?
so I start from wp-admin/edit-tags.php and paste his code right after where Slug field is defined but stuck on $tag what should be pass here?
Is there any plugin to add custom fields in category like More Field which is for posts?
First thing, there is a big red warning in that page:
So, clearly, you'd better use the new version.
Second, you should never modify core files (/wp-admin/edit-tags.php). The following Q&A explains where you should put code enhancements in your WordPress site:
Where to put my code: plugin or functions.php?
Restore your core files to its original state using the following instructions.
Try to always use the latest version of WordPress, Themes and Plugins, as having old code in your site may have serious security/performance implications.
The new version of Taxonomy Extra Fields has much more examples in its documentation, so probably your configuration doubts would change.
All that said, the plugin Advanced Custom Fields is able to put extra fields in Taxonomies (categories, tags, custom taxonomies) very easily, no coding required.
Okay:
To add image filed while add/edit category use this plugin it is awesome plugin.
http://wordpress.org/extend/plugins/categories-images/

Wordpress, alternative single post template

For a project of mine I need to define an alternative template for single posts.
To be more specific I need each post to be displayed as usual when the website is browsed but I need to create different single pages reachable from different URL to create a sort of a mini-website for each post.
(I'm actually using the WooCommerce plugin and what I need to do is to create a mini-website for each product. This needs to be something "outside" from the main website, with a complete different graphic template and is going to be reachable through a QR-code).
Hope it makes a bit of sense.
Thanks for your advices and/or suggestions.
Angelo
I think the easiest way to do that is by registering a custom post type for the special posts that get this special "single.php" template. Then, you can simply write a new single template titled post-[custom post_type].php. Any post you register of this type will use that template.
OR...
If you don't actually need them to be posts, it's even easier if you publish them as pages. By default, pages let you assign a specific page template in the edit screen. So you could make any number of custom templates. Just make sure you add the special header:
/* Template Name: Custom Page */
...so WP knows it's a page template.

Resources