Update WordPress Posts Inside Loop - wordpress

I have some processing inside my WordPress loop, and I want to "cache" the results so that the next time the post is displayed I can use the pre-processed info. The obvious place to store the results is as post metadata.
I have therefore incorporated a number of Update_post_meta calls into my code, along the following lines:
update_post_meta($imagePostID, "imageMeta", $imageMeta);
In this the value of $imagePostID is just the numeric Post ID, which I have already used to retrieve other metadata, so that's OK. I have also confirmed that the code is getting called at the right point.
However, the values are not getting saved, and it looks like for some reason the updates are just being ignored.
Does anyone understand why this is, and if there's any way to get the behaviour I want?
Thanks,
Andrew

Related

Passing Queries on multiple across multiple pages

When I generate a lead I get the values passed on via the URL Query which is the following:
?fname=[value]&lname=[value]&email=[value]
I’d like to know how I can carry this query over to the next page as well? (so the URL is passed over two pages instead of just the one).
So it would flow like this:
LeadPageExample.com -> Lead entered details -> LeadPageExample.com/Upsell?fname=Alex&lname=Smith&email=asmith#email.com -> Lead clicks on cancel or add to cart (I want fname=Alex&lname=Smith&email=asmith#email.com to be passed on again) -> LeadPageExample.com/checkout/?add-to-cart=312&fname=Alex&lname=Smith&email=asmith#email.com
Essentially I want the fname=Alex&lname=Smith&email=asmith#email.com query to be re-attached to the next link and passed on twice in this scenario.
To illustrate:
LeadPageExample.com/checkout/?add-to-cart=312&fname=Alex&lname=Smith&email=asmith#email.com
Any ideas? Is it possible? If so, how?
To be even more specific, I ONLY want this to happen on specific webpages on my wordpress site.
Thanks so much for the help.

Generate and display html table with user data from wordpress

Update: With the help of the answerer below I figured out how to do this. Basically I used a WP Query to get users and their user metadata and I sorted and placed the data in a for each loop in a table.
I'm new to PHP and I need some help. Basically I want to create a leaderboard with different user data. I want to display it in an html table.
This is kinda what i want:
Username GamiPress Points Time since last login
And I want the table to be populated with these data amongst others automatically. I want two versions one that is sorted with the 15 users who have the most points and one that sorts on the 15 users that logged in last.
Can someone point me to the right place on how I can best implement this?
I basically want to create the GamiPress Leaderboard add-on that I, unfortunately, can't afford, but with some extra fields.
There are multiple steps to do if you want to achieve this:
1) Add meta field to your users, so you can store the points. For example you can use "Advanced Custom Fields" plugin for this.
2) Write a function for adding points to this field. Define when this function will be fired.
3) Query the users ordered by that meta value and display it (get_users($args) might be useful).
4) For the Last-Login value you can use a plugin (google Wordpress Last Login) and write another Query and order results by that meta field. You can also write this by your own, here is a link I found: https://www.wpbeginner.com/plugins/how-to-show-users-last-login-date-in-wordpress/
I don't know if this is what you were looking for.
Or did you want to see an example code how you use a wp query and display data in html table?

Field is periodically updated. Need to show New and prior field when changed

For this report, I need one field (Sales Code) to only show if it has been updated. Periodically they change Sales code and I want a report to show the prior code along side the new code when it changes. Along with its part number and so on.
I was wondering the best way to go about tackling this request.
I tried to do _add_days -1 and compare the Sales code --> Sales code1. I dont think that will give me what I am looking for.
For example Sales code changes from AA --> AB.
I want to see New CODE OLD Code Part Number and so on...
AB AB 12345
The pattern you are encountering is called a slowly changing dimension.
Here's a wee free primer.
https://www.kimballgroup.com/2013/02/design-tip-152-slowly-changing-dimension-types-0-4-5-6-7/
You don't mention the structure of the data you're working with so it would be quite difficult for me to say what type you have other than the fact that you're trying to track historical data and seem to have it captured somehow rules out type 0.
Because of that, I can't come down from Mount Sinai with the solution but this can help you start to think through the problem.
In Framework manager have the modeler design the fields for SalesCode and SalesCode1
To only show if there was a change
Add a detail filter:
SalesCode <> SalesCode1
To control the context of time, have a separate filter like:
[Sales Date] between ?FromDate? and ?ToDate?

How to change values of parameters in PRD

In a report I set the client then the client's product. The client drop down is populated by a query that returns the client's id and client's name. Then I use the client's id on the second query to return that client's products. It works nicely up until I've selected a client and then a product and I want to change the client. On this case, the product's drop down displays the product query ids for the previous client.
I've googled a bit and found that there's a function to be added on the second parameter's "Post-Processing Formula" field. I've tried using something like that:
=IF(HASCHANGED[id_client];[id_product]="")
But it didn't work. What's the correct syntax for this? Is there an onchange implementation?
Thanks in advance,
I am using report designer 3.9.0. I performed a similar test. Both of the parameter's are drop down list and the second parameter automatically gets blank when first parameter has been changed.
This gives a syntax error on Report Designer 3.9
=IF(HASCHANGED[id_client];[id_product]="")
HASCHANGED needs ()
This does not give a sytax error
=IF(HASCHANGED([id_client]);[id_product]="")

D6: how to get at node fields in preprocess_page()?

i created a view that displays my homepage fine but now a modification is needed: i load 2 fields (images) in my view but need to only display one of those, depending on the value of a third (date) field and today's date. if date field is later than today, show image y and if its earlier than today show image x. this kind of logic cant be done in a view.
so in my template.php id like to output x or y as $vars['img'] in the preprocess_page function. im just wondering, how do i get at the values of those fields? its not a node but a list of node teasers.
the function gets passed &$vars but a print_r of those just shows the html output.
custom sql seems not the way to go.
when i load the view, i just get the html it outputs but (i think) i need the raw data to make the date comparison.
thanks for any pointers!
I'm sure there are some ways to do this, some more hackier than others. I would:
Make a template specific to your view
Create a preprocess function for the view and create a boolean variable, by checking which img that should be displayed.
Lastly I would alter the template slightly by making an if statement that checks if it should display img x or y.
This solution is pretty easy and straight forward, the downside is that it's not completely general as you most likely will need to know the names of the cck field names you are using. It's doubtful you would be able to generalize this anyways.
Edit:
To clarify a bit. You can look at the general views template that's being used, it will give you some insight as to how views prints the different fields. Generally getting at the fields is usually not a big problem when you have the $node object. The reason is that cck adds the fields to the $node object so you can access it there. I believe you can do something in the line of $node->field_[the_name] to get to the field. I would suggest that you use the devel module if you don't already and do a dpm($node) somewhere in the template where you loop through the nodes. That will enable you to see what has been defined on the $node object. It shouldn't be a big problem to print the img from there.
How about using preprocess_node() instead?

Resources