ACF location rule, show everywhere - wordpress

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.

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!

Passing a Wordpress ShortCode attribute value to a template

I wrote a custom post type to centrally manage lead forms, this has an accompanying short code so a lead form can be added to a page using [lead-form id="574"] - in this example, 574 is the Id of the lead form. When this is added to a page, I use a specific template for landing pages that include lead forms.
There are the fields in the custom post type that I need to access in the template, but in order to access them, I need the Id of the lead form first. I have included some screenshots that I hope will clarify this a little better.
Lead forms are centrally managed in a custom post type, in this example, 574 is the Id of the custom post
The code for the shordcode grabs the id using while( have_rows('pages', $atts['id']) ): the_row(); The fields used for the custom post type are a repeater of pages, which has a repeater of questions which has a repeater of predefined choices. These fields are created using the Advanced Custom Fields plugin. The shortcode is basically looping through pages/questions/answers and building a string that the shortcode returns. When adding a short code to a page, I specify a template in the "Page Attributes" section so I can include some styles and javascript.
template-lead-form.php is the file used for the "LP Lead Form" The string that is built in the shortcode is outputted in the_content(), however, there are two fields that I need access to that I can only get by passing in the Id to the lead form.
I'd search for your shortcode in post_content and get id from there. Regex isn't my strong side, but probably something like this:
preg_match('/\[load-form [^\]]*id="([0-9]*)"\]/', $post->post_content, $res);
After that you'd have id in $res[1].

Wordpress: get previous_post_link() based on custom field value

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.

Wordpress Add actions and filters only if certain condition met

I am customizing wordpress comments to add multiple custom fields. So i have added filters and actions to show fields, validate them, process them and finally show them in comments. I have written these and they are working fine.
However i only need them only for Post which belongs to specific category and comment is not a reply of any other comment.
I tried few things but nothing seems to work. Can somebody provide me a working solution.
Just to start, I think you could put conditions inside filters and not filters inside conditions. That said, for posts in category and category archives you can use the 'conditional tags' is category (for archive) and in_category (for posts):
https://codex.wordpress.org/Function_Reference/is_category
https://codex.wordpress.org/Function_Reference/in_category

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().

Resources