How-to count nodes based on cck filed data in Drupal - drupal

Nodes with cck checkboxes
need counting nodes based on cck data and displaing via views field
In drupal6 + taxonomy - there is a simple and fast function taxonomy_term_count_nodes()
But I`m thinking about d7 without taxonomy via cck custom field
Are there any API functions for counting nodes based on CCK fileds ?

I don't know if there is an API function to count nodes with CCK fields in D7, but there's nothing magical about API functions, you can easily create the function yourself if you need it. I don't know how the table structure is going to be, but if it looks like CCK in D6, you could do something like this:
function mymodule_field_node_count($content_type, $field_name) {
return db_result(db_query("SELECT COUNT(*) FROM {field_%s}
WHERE %s <> NULL AND %s <> '';",
$content_type, $field_name, $field_name));
}
You could probably make it prettier than the above, this is just to show that is you need to do something, you can just create a function to solve it for you. After all many API functions is often little more than a bit of logic and some queries that's commonly needed.

Related

Datatable creation with server side in wordpress using ACF plugin

I am having trouble using datatable in wordpress because my software and SQL knowledge is weak. As we know acf plugin data is stored in postmeta table. I want to create a datatable. I had problems with wp_query in array index. Not all data is available. Also, as you know, it makes more sense to use server side. But how do I pull the acf values ​​with server side and return it in a datatable. I couldn't find any good information on this. I also used the wpdatatables plugin. But it spills the whole table. I want to show the sample start_date and end_date custom fields of the post's id number. Also, some plugins create a special database for custom field values. This provides convenience. But although it makes sense for a new site, it is very difficult for someone like me who has entered a very special field value.
As I said above, is there a resource that will take the custom field values ​​from the postmeta and post tables and return them in a server side datatable? Thanks.
PS: Sorry for my bad english.

Wordpress Meta / Non-Meta Query 'OR' Clause

We've written a custom Wordpress API and the API has parameter called 'id'. The values that are passed into this parameter could be either Custom IDs defined in a custom field or (if that is empty) a Wordpress Post IDs. In other query languages I could accomplish this several different ways (either two WHERE clauses connected with an OR statement or else with a custom field that is populated with data from either column). I cannot, however, figure out how to do this in Wordpress. I feel like it should be possible, but I can't find any example.
If I was searching for two values in a Meta Query or a Tax Query, I could use an OR statement, but I can't figure out how to do this between a Meta Query and a Non-Meta Query.
Is this possible and how would you do it?

Feeds - Is there a way to pick an choose which feed items get created as a node

I'm grabbing a rss xml and using xpath parser etc to map the fields and create nodes. I've also used Feeds Tamper, Feeds Tamper php to take some feed items, perform logic and alter a fields content.
I'd like to know if there is a way to 'pre process' the feed items before nodes are created, perform logic on some source fields to work out i want to create a node from it?
See the Feeds API hooks, one of those in a custom module should let you alter the feed source beforehand - try hook_feeeds_after_parse to alter $result

Wordpress: Creating a thorough custom post type for recipes

I am currently trying to create a custom post type for recipes. My goal is to include the schema.org/Recipe and or hrecipe microformat and also have the ability to filter for ingredients in the future.
To do this I intend to have an interface with fields for title, photo, description, ingredients and instructions.
My question is: Should I create separate fields for each ingredient and each amount? Or would you say it is sufficient to just create one field for all ingredients? (also keeping the aforementioned microformats in mind).
http://schema.org/Recipe
http://microformats.org/wiki/hrecipe
Having ingredients as a single field is what is expected in both formats you linked to. Querying / filtering based on ingredient name will be slightly more complex...but you should be able to handle it.
There are 3 parts to this answer.
How should you save ingredients in WordPress
How should you allow users to modify the ingredients list
How should you display ingredients publicly
For point 1, you will have to give a bit of thought as to how you save the ingredient list and how you retrieve/display it along with how it is queried. One of the formats indicate you could have properties for each ingredient (still in draft).
You could save an ingredient list as a serialized PHP array, something like this:
$ingredients[]=array('milk','value'=>'125','type'=>'ml');
$ingredients[]=array('sugar','value'=>'1','type'=>'cup');
Since serialized PHP arrays are standardized, you could fairly easily write an WP query that takes it into account.
Keep in mind you will want to have a plan for when the 'value' and 'type' modifiers are set in stone and how to migrate what you saved if they are different.
For point 2, you could create a custom meta box that deserializes the PHP array saved and render individual controls for each ingredient along with controls to allow management (Add, Deletes, Updates).
For point 3....the easiest would be to get the value and manipulate it how you want in the output.

How to use Catalyst to search, select and display entries from my database

I have to use Catalyst in order to create a database and access it through a browser.
I have created a very simple database using DBIx-class and sqlite, just one table and filled it with some records.
I have managed to display the whole table and its rows using Template Toolkit view module and the code below into my controller.
$c->stash(ptm => [$c->model('DB::ptm')->all]);
Now I have created a simple search box in order to search the database and display any entries that match with the keyword, but I don't know how to pass the keyword to my controller nor how to implement the subroutine in order to achieve this.
I have searched for more than three days without finding any solution.
There are two completely different problems here.
Accepting arguments in Catalyst
Performing a search in DBIC
So, starting with the first one. Reading a query string.
$c->request->query_parameters->{field}
Then performing a search. Just call search instead of all and pass a hashref of your columns and values.
$c->model('DB::ptm')->search( { 'name' => $tag } );

Resources