Node titles as select list in views - drupal

I Have two content types.
School
Title (name of school)
location (geolocation - geofield)
User Properties (students)
school (entity reference)
class
Now I want to filter every school by title in a view as Exposed Filter. How can I display all names as select list? The filter works perfectly by typing the name.
Thanks!

Views Reference Filter module should do what you are looking for.
Alternatively you create the select list in a hook_form_alter on the view exposed filter form.

Related

Showing count of content based on the select list values Drupal 7

I have a requirement in which I need to show some content along with its count based on values in a select list. I wanted to display the allocated,released and resigned resources of a particular department in a selected date range. Using views, date range and department fields are created as exposed filters.
Created a content type for creating resources. The Resources content type is having action as a select list with values allocated,released,resigned. Department is another select list and date field is also added.
Please help me with an answer if views module is not enough. Provide some other solutions also. I'm using Drupal 7.
I figured out how to show node count in views. In my view I’ve some exposed filters and passed my select list cck field as contextual filter. If no result available I made the view to display summary as row count. In the template file, I’m planning to do some calculations for showing the resources count in and out of the project. Please correct me if there is anything wrong in this approach.

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

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.

drupal views dynamic filter

I have a Drupal website where I post tournament results.
I have created a content-type where i write the result for 1 person in the tournament. So the fields are like: Date of tournament, player name, final position.
If 10 people played in the tournament, I create this content for each player.
Now, I would like to create a table with views, to list all the players in the tournament, and the various info, like player name/final position. I can do that pretty easy by adding the fields and sorting criteria in views. But my problem is, what I should do next time we have a tournament. I would like to just use the same view settings, but without having to clone the previous view, just to change the date filter-criteria.
So, I need the user to be able to view tournament page, and then see the results for that specific tournament. Then if the user go to see a different page from another tournament, then only those results will show up.
And I wish to do it in a clean way, where I don't have to clone the view and just change date.
You can achieve this by making a view with a contextual filter. The contextual filter will handle a taxonomy or node reference so that you can use only 1 dynamic view. But in order to make this work, you might want to adjust your content type a little so that it's easier for your view to filter them:
Your current content type has all the information of a contestant/player (Date of tournament, player name, final position), so it would be better to name that content type Contestant.
Then create a new taxonomy or content type: Tournament which will handle the information of a Tournament. Keeping these separated is a better approach.
So let's say you have a taxonomy: Tournament taxonomy with all your tournaments set up. Then you can add this as a term reference field in your content type: Contestant.
(Add a new term reference field: "Tournament" with widget: select list.)
Create your view:
Filter criteria -> Content:Type (=Contestant)
Page settings -> Path: /tournaments/%
Contextual filter -> Content: Has taxonomy term ID
Override title -> %1
For each taxonomy term (Tournament) you have this view now has a page. So when for example you go to http://yourdrupal/tournaments/1 it will filter your view only for that tournament.
I attached an image so that you can see how I configurated my view

Asp.net MVC 3 view design

I have a table that has attributes not common to all rows that will be inserted, which mean my schematic will allow some columns to be empty and this will depend on the type selected.
The tables
Item table
ItemId
Name
Location
Typeid
Type table
Typeid
Desc
Upon a certain type selected (from a dropdown) in the form, some attributes in the item would be shown to the user and they would be have to be entered. How do I approach this.
You'll likely have a controller action (probably a controller) per table so you get separate urls for SEO. You'll also want a view per table as well as these values aren't really shared. You could create an ivory castle that would render a table given a generic List or DataTable, but if you're leaning that route, just use a control for it.
You can also do it with Javascript and AJAX. You can have a div which is hidden called 'item-form'. And on selecting one of the dropdown options, a javascript function can fill the item-form with the html for the selected item type (with the necessary attributes) and make the div visible.
Something like -
$("#dropdown").change(function(){
if($(this).val()==1)
$("#item-form").html(); //form with the attributes for type 1
else if ($(this).val()==2)
$("#item-form").hmtl(); //form with the attributes for type 2
});
You could fill the div's using calls to controller actions that are specific to the type selected which would return partial views.

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.

Resources