Reviewable Module Form Field Integrated Into Testimonial Module - silverstripe

I'm using the Reviewable module just for the form field that gives a star rating a user can select.
That produces a form field with a hidden field called 'score' for a 1-5 rating a user can pick.
I'm trying to modify this Testimonials module and page so I can use that rating field and it is submitted and written to the database. I'm having issues passing it into the validateSubmission function I guess because the rating is never stored in the database. It is always 0.
I'm probably just going to fork the Testimonials module so I don't mind hard coding the changes into the module instead of using data extensions.
I added the reviewable form field to the TestimonialForm FieldList but having problems passing to validate the submission function.
From TestimonialForm()
$fields = new FieldList(array(
TextField::create('Author', 'Your Name'),
TextareaField::create('Content', 'Your Testimonial'),
\Reviewable\RatingField::create('Rating', 'Please rate us out of 5 stars'),
));

Related

joining two custom post types for wp_query

I have two custom post types ("affiliate_codes" & "affiliate_tracker") that share a custom field ("affiliate_code"). In "affiliate_codes" I manage a master list of affiliate accounts (ie Affiliate Code, WP User, Percentage). In "affiliate_tracker", I have a form that adds new posts to the CPT passing fields such as Affiliate Code, Purchase Amt, etc.
I'm trying to create a report that is essentially a query that combines data from both of these CPTs, using the affiliate_code custom field to join the two CPTs together for the query.
A user could have more than one affiliate_code associated, so it would need to use the user ID passed in to grab all affiliate_codes associated to that user ID in 'affiliate_codes' CPT, and then retrieve all posts from 'affiliate_tracker' CPT that includes any of the codes associated to the user.
Is there a way to Join two custom post types as part of one query?
I initially tried to do this by nesting a second query within the main query.
Query 1 - pulling all posts from affiliate_tracker CPT and looping through.
Query 2 (nested inside the loop above) - uses affiliate code field to retrieve User from affiliate_code CPT
This works fine when I want to return all posts in affiliate_tracker. I also need to be able to filter the posts returned to only those associated with a specific user which is where I am struggling. Ideally I could have one query that combines the two CPTs by connecting posts via the shared 'affiliate_code' field and then can pull all posts from affiliate_tracker that have a code that is associated to a specific user. Not sure if this is possible.
Of course m8 , u can do it easily.
$args = array(
'post_type' => [ 'affiliate_codes', 'affiliate_tracker' ],
'post_status' => 'publish',
);
$query = new WP_Query( $args );
Above query gives you the all posts of these post types , now using following link you can filter them based on meta values based on your needs
Wordpress meta query parmeters

Access Gravity Forms fields on previous page (before pre-submit)

Here's the sitch: I'm using a multi-page Gravity Form in conjunction with an external API.
On the first page of the form, the user supplies a phone number. On a subsequent page, I need to send the external API the phone number in order to retrieve the user's current settings, which then must be prepopulated in other fields.
I know how to use gform_post_paging, but since $entry hasn't been created yet I can't use it to pull fields from previous pages.
gform_pre_submission/gform_after_submission don't help me because I need to make the API call prior to users reaching the end of the form.
I've also tried handling this via jQuery, by pulling and storing the value of the phone field on page advancement (e.g. var phoneNum = jQuery('#input_2_25').attr('value');), but I get "undefined" no matter what when using field ids. (It works fine, in the same location, looking for other ids on the site, so the issue isn't with jQuery.) I'm guessing this means that between pages, the form elements don't exist in the view?
How can I accomplish this goal (i.e., retrieving a value from a previous page in a multi-page Gravity Form prior to the user reaching the end of the form)?
All of the data is stored in the $_POST variable on each page submission. Gravity Forms has a helper function for accessing $POST data. The format for the variable name will be 'input{fieldId}'.
$value = rgpost( 'input_1' ); // replace "1" with your field ID

Wordpress - Add a user as custom field of CPT

Intro info:
I have a Custom Post Type (CPT) called Service.
I am already connecting users to this CPT using the plug-in 'Posts 2 Posts', this is a many to many relation, and these users connected to the CPT represent the 'team' of said Service.
Alright so here's the headscratcher:
Now I want to create a custom field in the CPT Service, which will be the Director of the Service. Say a field called 'Director' in which the value is a User.
Ideally, the value of the field Director is a User, not a string representing the user name or anything like that.
I have no idea how to start tackling this issue and some brightness on the subject would be strongly appreciated.
Thank you!
save it as post_meta. e.g if you have the user email:
$user = get_user_by( 'email');
update_post_meta($serviceid, '_director', $user->ID);
If you are setting this up in the admin section you can add a meta box and attach a action to save_posts to save a html field where you select a user. Google add_meta_box, there are a load of tutorials on this.

WP_Insert_Post change status depending on previous submissions

I have created a frontend form that allows logged in users to submit content to my wordpress site. The form allows them to submit to a custom content type. I would like be able to change the status of the submitted post depending on that users previous submissions. So if they already have 1 or more published posts then the submission goes to publish - if they don't then it goes to pending.
I know the argument that I need to change: 'post_status' => 'publish' - I just don't really have a clue how to start on the logic - let alone what the most efficient way of achieving it will be...?
first, set post_status as a PHP variable that is set by a function, and hard coded returned from within the function.
Then, refactor the function to do a separate WP_Query to find the count of published custom post types with the current userid as author. If >=1, return 'publish' else return 'draft'

Drupal subscriptions to taxonomy only

Playing around with the subscriptions module; i have some troubles getting it to send the right notification for right subscription.
Here's the situation :
I have a content-type of type 'work'; it has a cck-taxonomy field; when creating the content users choses one category in which his 'work' fulfills.
In user profil, under Categories (user/3/subscriptions/taxa) I choose two categories, lets say 'house work' and 'car work'.
When creating a new 'work' content I do not get the notification.
But, when manually select 'content-type' in user's profile of type 'work' I get the notification e-mail but independant to which 'category' i had chosen.
This is quite annoying since I only want the user to receive his notifications upon the taxonomy he has chosen, not for every new content of type 'work'.
Am I missing something obvious here ?
i have made it working fine for a taxonomy using the settings provided by the module. Concerning the rights i only allowed 'Subscribe to taxonomy terms '

Resources