Wordpress: get previous_post_link() based on custom field value - wordpress

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.

Related

How to insert a custom post field in a Wordpress Pod?

I recently started using the Wordpress Pods plugin and I'm trying to insert a custom post field in the Pod.
It is not working. Is there any way to do this?
I have created a pod named "network-section"
This pods works:
[pods name="network-section" where="id = '4'"]
[/pods]
However, I want to use the {#network} field because I have a lot of posts with different network categories.
This is not working:
[pods name="network-section" where="id = {#network}"]
[/pods]
{#network}"] is a custom post field.
Thanks!
your shortcode won't work like that I'm afraid. The ID field is looking for an integer that corresponds to the unique ID of a certain post. That's why your first example works but second one doesn't.
If you want to have a sub-selection of network-section posts, you should find a different way to select them instead of using 'ID" ,(which, by definition, will pull at max only one post).
For instance, you could add a custom taxonomy and use that to filter by in the shortcode, or sooner other field.
The easiest solution might be too create a field in your Post called "network category" then door each of your posts you can give them a particular number.
That way, in your shortcode, you can do:
[pods name="network-section" where="network-category.meta_value = '2'"][/pods]
N.B. you will probably need to use that ".meta_value" to get the right bake in your shortcode, but it depends on how you sweet it up. AND you'll need also need to add your html and other code somewhere (can be in a Pods template or even between shortcode open and close tags) otherwise there will be nothing to display...
Good luck!

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

ACF location rule, show everywhere

I am using the ACF (advanced custom fields) plugin in WordPress. I have a group and I want it to show at every page/post/custom post type/etc.
At rules, I can say that a group will only be shown at, for example, a certain page. But can I say that I want it to show everywhere?
Do you want the group fields to be shown at all the editors, or do you want the fields filled in at a certain page to be shown at other pages also?
Adding a group to multiple page/posts types
This is easy, you can apply more than one rule to a group.
so:
If type is same as post +
if type is same as page +
and so on...
Use a certain field's input from one page on other pages
If you have filled in some custom fields on a certain page, and you want to use that same input on other pages, use the following line:
<?php the_field('field_name', original_post_or_page_id); ?>
Creating a global group
You can also use a global group to be shown on all pages. I use this extension: https://www.advancedcustomfields.com/add-ons/options-page/
Well, the problem seemed to be, that the whole piece of code was inside an function, and the function was made into a shortcode. When I tried to get, for example, the title of a custom post (in this case the post type 'case'), it simply would not communicate with this post type, for some reason.
I took the piece of code out of the function, and called it directly, which seemed to work.

Display all custom attributes Woocommerce

I'm working on a project where I want to display product's image and customs attributes from Woocommerce.
I already set attributes like this
I want in my php code display all the attributes (title et terms).
I already try <?php $product->list_attributes(); ?>. It works fine but data are displaying in <table>. I want to customize the display.
Thanks for your help !
Whenever I get stuck with a custom method like this in WooCommerce, I try to resort to the docs to see what is going on.
If you inspect the source for this method, you'll find that it's actually using a custom template single-product/product-attributes.php to output this table you're seeing.
In order to change the output, you have two options:
Override the template via your theme
Observe single-product/product-attributes.php and use the information there to write your own custom loop in your original template.
The second option means that you'll likely use the get_attributes() method, instead of list_attributes().

ACF - Template Assignment Seems Permanent

I've been using the Advanced Custom Fields (ACF) plugin for quite a while now. It's absolutely awesome but I'm experiencing some behaviour that is not the norm.
I've noticed that if I change the page template that is assigned to a set of custom fields, the pages that ran off that template (no longer assigned to those fields) effectively holds onto those custom fields and thus renders correctly on the site.
E.g.
ACF Partner Fields are assigned to a Partners Template that has a number of pages running of it.
If I assign these fields to another template, all of the pages running of the Partners template, still render correctly.
I'm not sure I've ever experienced that before and it is causing issues with another plugin that is being integrated for translation.
Any ideas what might be happening?
All time and help is appreciated.
When you change the template, your only changing where those fields appear on the backend and what post type or location they write to in the database. The database table for those unassigned posts still contains the information form those ACF, they just won't be written to any longer.

Resources