Advanced Custom Fields - Filtering a Post Object Field by previously chosen Taxonomy - wordpress

I have a custom post type called Event in which I want to add a location chosen from a large list of locations. To make this process easier I want to filter these locations by a category called locality.
To achieve this I have created a custom post type called Locations and a custom taxonomy called Locality. A field group holding two dropdowns one for Locality (Taxonomy) and another for Locations (Post Object) has been added to each event.
What I haven't managed to achieve is the filter of locations by the locality chosen.

I don't believe you can dynamically filter the choices of one custom field based on the current choice of another, and change that choice on the adminend. You can filter the choices that show up in your fields with a query modification that's very similar to WP_Query, and I'm pretty sure that can't be done on the fly.
I would almost cheat and instead of making posts with taxonomy assigned to them, include both the locality and the location in the post name itself.
So say, post [Museum of London] with taxonomy [London]
would become
[London][Museum of London]
[London][Hyde Park]... etc
or something similar. I'm presuming you only want to assign one location to any specific locality...
Then I'd create a relationship field and whenever I'm looking for Museum of London I'd type
London Muse...

It looks like this question is stale by now, but you would make your life easier if you added two custom fields to Event - location and locality. That way you don't have to join two tables and can easily use WP meta_query to filter posts.

What i understood is that you want that whenever you select the locality the location for it should be shown there and at last you can filter Events with locations.
=> To set location you assigned two drop-down for locality and location. You should use ajax. when i select any locality than the next drop-down has the options for the selected locality.
=> To add value in event post: you might have two options
i) you may add location as taxonomy and search using "tax query" to filter
ii) add location as parent of event and search "child of" in wp_query to filter

You have two options:
Program custom js to filter the locations field onchange of the localities field. This would not be so hard to do, because ACF sets the field id's for every field in their html. You can enqueue this js script in an admin hook (probably admin_enqueue_scripts, check this solution) and filter for the custom post type.
It can all be done in the ACF gui, but it's a bit of a trick, also because of the fact that the conditional logic for acf's taxonomy field is lacking. What you have to do is create as many Location fields in the Event acf fields as you have localities. Then set these locations to specific localities. Now comes the weird part. You would want to set the conditional logic to display if the locality is e.g. Russia, but it lacks a 'specific value' field. So you have to set two rules, one to set the 'greater than' and one to set the 'lesser than' for the id of the locality. . This will be a pain if you have a lot of localities, but it might be a good option if your localities list has no more than a few items. If you name the location fields all 'location' than you can just get the value with get_field('location'). I tested this and there is no conflict in naming all the location fields location. ACF has done a pretty decent job there, having unique names for these fields also to be able to name these fields as you whish.

Related

calling of one taxonomy from another taxonomy, so both of them have used in the same content type

Can we call one taxonomy term from another as a parent and child relation for example I need to click on product category and that show me product series page and when I click on product each series that will lead me to actual product detail means node, so I have two taxonomies category and series I am about to click on category to carry me to series page and then to click on series page to carry me to product detail page on the concern series”
no codebase problem
i am expecting that these two taxonomies may be used as i have mentioned in the question summary but, i can't do it so i hope some help in resolving this issue
Let's look at this answer, I hope it will help you.
Taxonomy terms from the same vocabulary filtered and referenced on multiple content types
To do this you’ll need to have the Entity Reference module installed. So get that out of the way quickly with drush dl entity reference -y and drush en entityreference -y if you haven't already.
First up, we need the taxonomy set up.
Let's demonstrate with the help of an image.
You’ll notice that these terms could be more or less grouped into two categories: Transport and Sleeping. One term (couchette) kinda fits both criteria and is there to exemplify the reason for not using 2 different vocabularies to handle the issue. Now we need to technically make the distinction between these terms as well and since they are entities, we can use a field for that.
So we can now go ahead and add a new field to this vocabulary of the type List (text) with whatever widget you’d like (and let’s call the field Type). You should make the allowed number of values unlimited and put the following in the allowed values list:
Edit each term and select the appropriate type. As expected, for the term couchette, you should select both options.
Now that we have our taxonomy squared away, it’s time to create a View that will handle the filtering of these terms. Because if we now add the Tags taxonomy term reference field to our content types in the normal fashion (as it is already present in the Article content type) we’ll be able to select all the terms in the vocabulary for all the content types. And that's not what we want now.
So create a drupal 7/8 View that shows taxonomy terms of the Tags vocabulary - let’s call it Tags Filter. Add 2 displays of the type Entity Reference and a filter of the field we added to our terms earlier. So for instance the first display can show the terms which have Sleeping selected and the other one can show terms which have Transport. Save the View and you can close it.
Now finally we can edit our content types and add to each a new field of the type Entity Reference with a select list widget. For the target type select Taxonomy term and under Entity Selection choose the following: for Mode, go with Views: filter by entity reference view and then select the View in question - one of the two displays which we created earlier. In the picture below, I named one of the displays

Make Drupal 7 Group by always show grouping field

I have a Drupal 7 view similar to the one described here: Drupal 7 Views - list group by field
I wish to have all the groupby fields always appear even if there are not members of them and ideally I wish to put a default value in such a list.
eg:
Foo:
-Jay
-George
Bar:
-Barry
Boo:
Sorry no entries at this time!
Suggestions?
If none of what you are fetching with the view is associated with the group 'Boo' then the view doesnt know it exists, so would never be able to show it but say there is no results for it.
What i would recommend is creating a taxonomy vocabulary with the terms: Foo, Bar, Boo.
In whatever content type your names belong to, create a term reference field, and link them to the terms.
In the view, fetch the taxonomy terms, create a relationship to the content type that references the taxonomy, and pull those through based on that. There is a setting in views for multiple results to combine into one field (so you would want to do that). Then you could add the 'Sorry no entries at this time!' as a field's no results text.
So to recap: VIEW => TAXONOMY TERMS => NAME CONTENT

Add view filter to retrieve content associated with one or more Taxonomy Term IDs

I have created a Drupal 6 view which has two "Taxonomy: Term" (Term ID) filters, for two different taxonomy terms. I need to create a feed that pulls content that is associated with a OR b, or that is associated with a AND b. Currently, nothing is displayed because it seems that the logic of two filters is AND, not OR.
How do you pull content that has the logic OR with Drupal views?
It does work if there is only one filter, but as soon as I add a second filter, zero records are found.
The OR filter is not built in to Views2. For ways to get around this, see http://groups.drupal.org/node/16173. And this old post might help as well OR operator in Drupal View Filters

Views 1: Filter by custom table/field (or using Argument Hand. Code)

I have a page which should list nodes. The views is called from a locality page (a taxonomy term page). What I need is almost the same as using the Taxonomy: tid in arguments and passing the tid.
I can't use the term_node table, as (for other reasons) we have a custom table term_node_hierarchy (with nid and tid only). The table term_node_hierarchy is like term_node but also saves the tid of the parents (from an "external" code)
I've been looking for options but still no joy.
Currently I'm building an array of the nid's that should be displayed on the current page, and passing them like print views_build_view('embed', $view, $matching_nids); but the Argument Node: ID states This argument is a single Node ID. As said, only the first node is displayed when printing the views. It would be great if it could filter on more than one nid.
I'm open to any kind of suggestions on how to do this.
Thanks
You could create your own module for this. You could populate the $page_content variable with the results of your own custom query where you allow the user to sort against multiple nids. You could do this a number of different ways. You could display a list of the existing nids with corresponding checkboxes, so that, when the user clicks submit, all the nids that match the selected checkboxes get used in the query. Then you just display the result of that query. That's the easiest way I can think of to offer that degree of flexibility.

Drupal 6: Taxonomy splot up in managed fields?

So you have two taxonomies, namely: "Business Type" and "Location"
This is assigned to a node called BUSINESS. In effect, when the user creates a BUSINESS node, her has to choose for example, location "New York" and type "Information Services". My problem is when:
a) Capturing the taxonomy, and
b) Displaying the taxonomy
I want the two terms to be separated from each other. I.e. I want to be able to move the two terms individual positions in the MANAGE FIELDS view, so that they can be grouped or placed seperately. Currently, Drupal only allows one entry, called "TAXONOMY" which is effectively the two terms next to each other.
This is what I have:
alt text http://www.namhost.com/have.jpg
This is what I want:
Bare in mind, I need to be able to use this with Hierarchical Select, which means Content Taxonomy is not an option.
You'll have to separate your problem in 2 parts:
The form filling part, which will have all vocabularies together to the editor.
The content display part, which you'll be able to separate vocabularies.
I'll cover here more the second part, about displaying.
Use the CCK computed field module and create one field for each vocabulary you want to display. Position this field where you want them.
Configure each field as follows:
On the Computed Code, put something like this:
# Get vocabulary ID from its management URL (/admin/content/taxonomy/edit/vocabulary/[VOCABULARY_ID]) and set here:
$node_field[0]['value'] = "5";
# Also, configure this field as 'Raw Text' on Display Fields
On Display Format, use this:
$vocabulary_id=$node_field_item['value'];
$terms=taxonomy_node_get_terms_by_vocabulary($element['#node'], $vocabulary_id);
foreach ($terms as $tid => $details) {
# The taxonomy_get_textual_term_hierarchy_by_id() is implemented on the SolutionHub's theme template.php file
$textualTerms .= taxonomy_get_textual_term_hierarchy_by_id($tid);
}
if (isset($textualTerms)) {
$display='';
$display.=$textualTerms;
$display.='';
}
The taxonomy_get_textual_term_hierarchy_by_id() function is specific to my site and is defined in DRUPAL_ROOT/sites/default/themes/mytheme/template.php and simply rewrites the taxonomy term text in a fancy way to show its entire lineage. So instead of "apple" I'll get something like "food > desert > fruit > apple". I won't paste it here cause it is out of scope.
If your problem is to reposition the vocabulary in the edit form, I would suggest the Content Taxonomy module.
You are stuck with the two taxonomies appearing together in the input form, they come as a package. Taxonomy should be used as a classification system (like animal kingdom classifications) so the terms to belong together in physical space.
But for the other half of your question, keep in mind your users will see the 'Business type' and 'Location' labels in the input form, not the generic 'Taxonomy' label that you see when managing fields.
maybe you could do better with cck. by enabling text (comes with cck) you can add text fields. and you can easily use them separately, use them with views, templates, etc.

Resources