I am able to display the region based on IP using the below code:
if ($_SESSION['smart_ip']['location']['country_code'] == 'IN'): ?>
India content specific
Now I want to use a taxonomy term like India and display the content, whichever posted in India.
I want to print the nodes, which has term as India only if the above condition satisfies:
foreach ((array)$taxonomy as $item) print $item-> India
If you have a catalog that allows you to identify the geographical location some session is associated with you could add an attribute 'search terms' to each entry in that catalog. That way once you identify the location in the catalog the session is associated with you have a list of search terms. You can then use these seach terms to filter a database query for all posts to get only those posts that contain one or all of the given search terms.
The list of search terms for the example india might start with (India,Bhārat,Gaṇarājya,...)...
Related
I have a view "news" which is listing nodes from "news" content type.
This content type contains a field "countries" which is multiple.
So, my news "Test 1" will have a field countries like this one :
France, United Kingdom, Spain
My users have a field "Country".
What I want to do is to add a filter criteria in my view meaning :
News.countries = Users.country
At this moment, when I try to do it, I cannot set a "must be equal to" to News.countries, certainly because it is multiple.
Can you explain to me how should i do ?
You should use a contextual filter. Add a relation to current logged in users country and add a contextual filter for the field new.country and use the relationship.
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.
I am creating a business listings and Advanced Custom Field (ACF) helps me to create the backend form.
The question is, how do I get the sub category of a main category only if I set the condition.
For example,
I have 100s of City names as City Taxonomy
I have 100s of Area names as sub category of the City Taxonomy
I have created a form that includes these 2 fields.
City:_________ (Drop down selection of City Taxonomy)
Area Name:_______ (I want this sub category drop down to show up based on City selection above)
Is this possible? Or does it require coding to make it work?
I have searched enough and I could not find even a premium plugins to support this.
I can simply set these 2 fields to pull data from City Taxonomy but the data entry becomes very tough with hyphen appearing before sub-city Taxonomies and possible duplicate value under different city.
Thanks in advance.
I have two vocabularies ( Man and Woman ) with their regarding terms.
These terms are used as fields in content types Men and Women too. Now i wanna filter contents by content type and those vocabularies' terms by Views module ( custom view with name gallery ) in help of Contextual Filters as below :
http://mysite.com/gallery/content-type/(Man or Woman)'s terms
something like this :
1 - http://mysite.com/gallery/men/jean
2 - http://mysite.com/gallery/women/jean
1st url "jean" term is for vocabulary Man and the 2th url "jean" term is for vocabulary Woman.
I should add 3 Filters, one for content type one for terms of Woman and one for terms of Man. but the two Man and Woman Vocabularies should be filtered at one %.
I know by using this kind of path gallery/%/% the work should be done BUT filtering from two vocabularies' terms in the second % in url is my problem.
any help would be appreciated.
Views won't be able to distinguish between "jean" in url #1 and #2 if you use a taxonomy filter validating with "tid from term name".
The quick and dirty way to solve this is with two views: gallery/men/% and gallery/women/%.
They will be identical except in their term filter, which you would set to validate by the appropriate vocabulary. (They would also differ in their regular filter for content type.)
The programmatic way to solve this would involve using the first contextual filter as input to the second so you can limit by vocabulary. For example, something like
$vocabulary = $view->args[0]; // assuming this is the machine name
$term = taxonomy_get_term_by_name($view->args[1], $vocabulary);
return (!empty($term)) ? $term->tid : 0;
I'm starting my first Drupal project, pretty excited :) I have a question;
the project is a hotel directory site. at sidebar I have locations list (London, Manchester, Liverpool, etc..) and filter the hotels related on location click.
So, how should I create these cities? Should I put them manually and give links manually depending on location id? or is there any better way to create this location list and linking filtering dynamically (via cms, or custom module, etc...)
Appreciate advices!!!!
This would be a good example of when to use the core (part of the base Drupal software) Taxonomy module. With Taxonomy you can set up one or more lists of terms that describe some or all of your nodes. For example, you can have a list of locations, a list of amenities (pool, sauna, golf course, etc.), and a list of price ranges (low, medium, high).
For each hotel you can select a location from the locations list, one or more amenities, and a price range. Then you can select all of the hotels that match one of the lists, using a neat feature of Taxonomy where it will return a list of those nodes.
The lists of terms are called "Vocabularies", and you'll want to create a vocabulary for each list. Go to Administer -> Taxonomy -> Add Vocabulary. Give it a name, like "Location" a description if you'd like, and choose the content types that it should be allowed to be associated with. (In your case, the hotels should probably be a custom content type that is different from the Page and Story types, but for trying this out, just pick Page for now.) There are several checkboxes at the bottom to decide on: Don't check Tags or Multiple Select, as these allow free tagging by users (images users making up city names) and also allow a node to have multiple locations. Do check the Required checkbox, as each hotel should have one.
Click Save and then click Add Terms on the vocabulary list page, and add a few locations. Then create a few hotel nodes (Pages for now) and you'll see that there is a new section in the Create Content page that is a dropdown selector that contains the locations. Choose one for each hotel, and add a few hotels in the locations that you just created.
To select the hotels for a given location, you will need to know the path associated with each term. Go back to the Taxonomy admin page and choose List Terms for the Location vocabulary. On the Terms in Location page you can get the list of hotels for a location by clicking on a location's name. The resulting page's path (e.g. example.com/taxonomy/term/2) would be what you'd use in your menu for that location. Each location will have its own term number that would be at the end of the path.
This is the simplest way to use the Taxonomy module, but it works really well with other modules like Views. Using Views you can control the format of the list of hotels for each location.
For more information, see the Taxonomy documentation and especially this sub-page called About Taxonomy.