How to display all values of a custom field in a given category? - custom-fields

In a WordPress category that has posts in it, each post has a custom field that has a value (usually a number).
The question:
How do I get all the custom field values from all the posts from that category?
(I want to be able to use those values independently (to strip non-numerical characters, make average, etc).
Thank you,
Puiu D. - Romania

get_post_custom returns a multidimensional array with all custom fields of a particular post or page.
EG:
$custom_fields = get_post_custom($post_id);
You can get all your posts in a specific category using get_posts and loop through them to get their specific custom fields.
Function Reference: http://codex.wordpress.org/Function_Reference/get_post_custom

Related

Filter all rows in a column in body for API call using POSTMAN

I would like to know for a search filter what should be the ideal way to list all types of values from a column using the search term - (search.in(GameType,'Multiplayer' , ',')) from body in POSTMAN. From what I've seen boolean operators are used to filter multiple columns in a table, but for a single column there are implementations for specific values like above. Precisely, I want all the types from the column Gametype in my search. Can you share some thoughts/ideas on this?

ActiveAdmin: access to the result of filters

I want to display few stats on top of an ActiveAdmin index page.
Let's say I have a car model, with a color attribute and a year of fabrication. On the top of my index page, I want to display the count of red cars. But I want that count to reflect the use of filters; if I choose to show only cars built in 1995, I want the red car count to change accordingly.
How can I access the filtered list? I guessed the existence of a variable containing the result of filter action, but I can't find it.
Turns out you can use the variable collection anywhere in your index.
Something like this is working perfectly, and reflects the state of filters:
index do
div "Total: #{collection.count}"
column :attribute1
column :attribute2
actions
end
Another way is to use ransack, with this:
ModelName.ransack(params[:q]).result
But it does a useless query, call ransack again for no reason.
Inspiration found in this question.
Use this method
apply_filtering(collection)
Inspiration found in this question

Generating values for dropdown ONLY for 'C' of CRUD

When choosing 'Add' in CRUD, how best to generate a list of choices to pick from a dropdown?
For U/update - just display what's there...
The field contents starts with a letter, followed by five numeric digits:{A-I,K-N,Z}#####
Each letter has a different 'max' value for the numeric part.
So when adding a new record, I'd like to offer a listbox with one of each letter and that letter's highest numeric value + 10.
So, if the max 'A' as A00120, and max 'B' B00030 (etc) the listbox would have A00130 and B00040.. etc
Save the user having to figure out which is 'next' when generating a new record.
? Thanks,
Mark
This time I'll not be able to come up with ready to use solution, but I must say - everything is possible with ATK4. You just have to customize and extend it to fit your needs :)
Speaking about your question above - I guess you have to split it in multiple parts.
First part is about how to show select box on Create and readonly or disabled field on Update. I guess you can make some custom Form field or pin some action to existing Form Field hook. Not sure exactly what's better in this case.
Second one is about data structure. I believe that this field actually should be 2 fields in DB and maybe (only maybe) merged together in ATK model with addExpression() just for user interface needs to display these 2 fields as one field easily in UI. Maybe such concatenated field will be useful also for searching, but definitely not as only one field stored in DB. Imagine how hard it'll be for DB engine to find max value if such field. Store it like type = letter, num = number and then search like SELECT max(num)+10 FROM t WHERE type='A'
Finally Third part is about how to generate this next number. I read your question 3 times and came to conclusion that actually you don't have to show this +10 numeric value in UI at all if it's hardly predefined anyway. Actually that'll not work correctly if this will be multi-user system which I guess it will. Instead just show simple select box with letters {A-I,K-N,Z} and calculate this next value exactly before inserting data in DB. That can be done using models insert hook. This will be much more appropriate solution and will be better for UI and also more stable because calculated in model not incorrectly in UI part.

Combine multiple columns containing similar values into one column for use in graph inside Crystal Reports

I have 3 fields, Action1, Action2 and Action3 contained in one report. Each Action field is selected from the same list of values. I would like to graph a count of these values by the value of the field and not field itself. I need one graph and not one graph per Action field. I have tried to combine the field values into an array in the details section, but the report shows the concatenated string values "Action1, Action2, Action3', as a single value in the graph. I tried to graph using "on change of", but it will only allow 2 fields and not 3. Is there a way to count these values regardless of the Action field where they are found?
I have been working with Crystal for years, but can't figure this out for whatever reason.
I was never able to find a solution to this issue inside of Crystal Reports itself. What I ended up doing was creating a stored procedure in SQL to use as the data source. In the stored procedure I basically performed a cross join such that there was only 1 Action returned per record. In CR I then was able to summarize the Action field values.

How to keep track of selections in sequential form

I have what is essentially a form, only the fields depend on the previous selections, and the type of form object aren't always typical form objects.
For example, the first choices are simply in the form of links. It could be a list of teachers, where when you select a teachers name, the classes that teacher teaches is then displayed in a drop-down list. Then once a class is selected, the available dates and time are displayed in a calendar. Once a date/time is selected I need to know all of the selections that were made -- the teacher, the class, and the date and time.
How would you recommend keeping track of these selections? I'm using ajax, and although the form fields are hidden at times, i can still access their values. The one exception is the teacher selection. Since it's just a link, I pass the selected value to a method, but then I've lost the selection. I could store the selection in a hidden field, but is that really the best solution?
Thanks!
I would use a session store on a controller action. Then once it's complete extract all the gathered information.

Resources