I am new to Moodle and need some assistance creating (year only) date selector.
In the code below I have a few entry fields.
If possible, I would like to customize the bottom 2 date selector fields to display only years for the user selection. My attempted workaround was to use the 'PARAM_INT'as a data type, which does not seem to be work. It also would not stop users from entering years such as 0000 or 1000. Thanks for your help in advance!
$mform->addElement('text', 'article_type', 'Article Type');
$mform->setType('article_type', PARAM_TEXT);
$mform->addElement('date_selector', 'print_article_date', 'Print Article Date');
$mform->setType('article_date', PARAM_INT);
$mform->addElement('date_selector', 'earliest_article_year', 'Earliest Article Year');
$mform->setType('earliest_publication_year', PARAM_INT);
Do you need a date selector? Maybe use a drop down select for the years instead and store the year rather than a date.
$options = array_combine(range(1900,2018), range(1900,2018));
$mform->addElement('select', 'earliest_article_year', 'Earliest Article Year', $options);
$mform->setType('earliest_publication_year', PARAM_INT);
Incidentally, you should store strings in the language file.
If its a local plugin, this the language file would be /local/yourplugin/lang/en/local_yourplugin.php
Then have something like this in the language file:
$string['earliestyear'] = 'Earliest Article Year';
Then change your form code to:
$mform->addElement('select', 'earliest_article_year',
get_string('earliestyear', 'local_yourplugin'), $options);
Related
As the question states, how do I copy an ACF field from one post to another? This is what I have so far. Any help would be appreciated.
add_action('save_post', 'dupe-expiration-date');
function dupe-expiration-date()
{
// Gets expiration date from 'Homepage' page
$date_field_data = get_field('sale_expiration_date', 2361);
// Sets expration date on 'Deals' page
update_field('sale_expiration_date', $date_field_data, 34412);
}
Essentially, my code works. I don't know PHP so when I created the function dupe-expiration-date, I didn't know I couldn't use the character '-' to name the function.
Once I corrected that issue, the code worked as intended.
I need to retrieve the birthday of a student from the database and set it as the birthday of a student entity. Then I need to load that data to a form.
$birth_day = strtotime($student_[0]['birthday']);
$birth__day = date('Y-m-d H:i:s',$birth_day);
$student->setBirthday($birth__day);
And in the form builder I have used the below code
add('birthday', 'birthday',array(
'data' => new \DateTime(),'placeholder'=>'-SELECT-'))
Instead of the birthday that particular student, it shows the today's date.
Can someone please explain what should I do to load the birthday instead of the today's date.
Thankyou in advance.
When you use the 'data' option, you are setting the default value for the field so in your example you are setting it to a new Datetime (today).
Here is the symfony doc page about it http://symfony.com/doc/current/reference/forms/types/form.html#data
Like #abdiel suggested, remove the data part.
I've been struggling (I'm a newb) on how to have The Events Calendar print a list of all events within a specified year. I researched this need heavily online and I'm surprised that there's limited info on the subject. The list is simple really. It just needs to be a linked title that sends the user to the actual event page.
My approach was to create a custom [shortcode] in functions.php so I could place the list on any WordPress page or post that I need.
The custom shortcode PHP is the following.
add_shortcode('yearList', 'yearList');
function sayHello()
{
echo '<h1>Hello World</h1>';
}
I added this to the functions.php file within the Genesis child theme root. The text echoed fine so that part is good to go.
After researching the forums at Modern Tribe I came across a useful page that reviews the tribe_get_events function. Here's the page for those wondering.
Any way, the code in this page gets me close so I know I'm on the right track.
The PHP that I'm using within the created shortcode function is the following.
// Setting up custom function called yearList
add_shortcode('yearList', 'yearList');
function yearList()
{
// Ensure the global $post variable is in scope
global $post;
// Retrieve all events desired year. Only eight printed out of 80.
$events = tribe_get_events( array(
'eventDisplay' => 'custom',
'start_date' => '2014-01-01 00:01',
'end_date' => '2014-12-31 23:59'
) );
// Loop through the events: set up each one as
// the current post then use template tags to
// display the title and content
foreach ( $events as $post ) {
setup_postdata( $post );
// prints the title for each event.
echo '<br><br>';
// WRONG WRONG - This is below is what's throwing me.
echo '';
//the_title();
// echo tribe_get_start_date(); This shows the start date and time after the event title I slept this for now.
}
}
I have two questions.
Why would the loop only show nine titles when I have over 80 stamped
for 2014?
How can make each line be a link to The Calendar Events actual event
page? I've tried to employ this with no luck.
Thanks for any help on this.
For your first problem, try adding posts_per_page => -1 inside your $events = tribe_get_events( array( ... ); statement. The default limit must be set to 9 posts somewhere. If that doesn't work, try replacing -1 with a large number.
For the output issue, you can't echo an echo in php. Try this instead:
$ev_link = tribe_get_event_link();
$ev_title = get_the_title();
printf('%2$s', $ev_link, $ev_title);
I am trying to download a click performance report from the AdWords-API. For my example I am only selecting the Date field.
function DownloadCriteriaReportExample(AdWordsUser $user, $filePath) {
// Load the service, so that the required classes are available.
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields = array('Date');
// Filter out deleted criteria.
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('DELETED'));
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Criteria performance report #' . uniqid();
$reportDefinition->dateRangeType = 'YESTERDAY';
$reportDefinition->reportType = 'CLICK_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
// Exclude criteria that haven't recieved any impressions over the date range.
$reportDefinition->includeZeroImpressions = FALSE;
// Set additional options.
$options = array('version' => ADWORDS_VERSION, 'returnMoneyInMicros' => TRUE);
// Download report.
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
printf("Report with name '%s' was downloaded to '%s'.\n",
$reportDefinition->reportName, $filePath);
}
The error I get ist: "ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT".
The same script runs with no problems for the Criteria Performance Report.
https://developers.google.com/adwords/api/docs/appendix/reports#click
The issue is with your predicate - AS "click performance report" does not have a 'status' field - so remove that predicate - that is most likely your problem -
also remove the
$reportDefinition->includeZeroImpressions = FALSE;
You don't need this since this is a click performance report -
and the date field is a segment - if the above does not work , then maybe try to add at least an attribute , like GclId or something -
Since this report can only be run for one day , it seems silly to just be selecting the date.
Hope this helps -
See this link for reporting fields - if you plan on running a variety of reports you will find this link very useful
https://developers.google.com/adwords/api/docs/appendix/reports#click
Is there not a little bit more info after that error such as Trigger = 'status' or something? That will often tell you what column is causing the error.
If that does not help then run the GetReportFields.php file to see a list of the names and check they match the ones you are trying to use.
Also the names do change between versions so the example they show might only have names that work in the v201402 version and maybe you are trying the v201309 version. I had this issue and once I used the new library it was fixed.
From the documentation fro the Click Performance Report (https://developers.google.com/adwords/api/docs/appendix/reports/click-performance-report):
"Note: This report can be run only for a single day and only for dates up to 90 days before the time of the request."
So, I imagine you can't select the Date field, because it is implied by the single date you must filter by.
I know it's late, and you've probably moved on, but maybe this will help someone else with the same issue.
I think it is a common case:I have three categories: Past, Current, Upcoming.
Now I write a post about next month's event. I put this post in Upcoming category.
What I want is a scheduled category change.
i.e.:
This event runs from Dec 1 to Dec 10. From now till Nov 30, this post is in Upcoming category (I select this category when creating this post).
On Dec 1, this post will be in Current category automatically, till Dec 10.
On Dec 11, this post will be in Past category automatically.
I did a search and did not find such plug-in.
Basically, I want the publishing page to have two extra options:
Option 1: Change to Category _ on _
Option 2: Change to Category _ on _
It sounds like a workflow question. I searched workflow related plugin but still with no luck.
Any suggestion on how to implement this? I can write a plugin but I am new to WP. Could anybody suggest me which API/functions to use?
Thank you!
First off: There could be a plugin out there that can handle what you want to achieve. If you need a simple events calendar, I am almost certain this can be done with existing plugins. Off the top of my head, MyCalendar would be one such plugin. You might want to search the wordpress plugin directory for further options, before you dive into coding this on your own.
That being said, if you can't avoid constructing this yourself, because you're case is to specialized, this should get you started:
Either use custom fields to add the extra meta-data of start and end date or make the events a custom post type of their own. Explaining the use of custom post types en detail is past the scope of a concise SO answer.
If you opt for the simpler way of adding two custom fields called start and end (or the like), you will have to either run a php script as a cronjob via your server or make us of the WP-Cron Functions to compare the current time with the start and end date and change the category accordingly.
To provide you with some useful code (which would go into your self-written plugin), the following php snippet should point you in the right direction:
register_activation_hook(__FILE__, 'your_activation');
add_action('your_daily_event', 'change_categories');
function your_activation() {
$first_time = time(); // you probably want this to be shortly after midnight
$recurrence = 'daily';
wp_schedule_event($first_time, $recurrence, 'your_daily_event');
}
function change_categories() {
$old_name = 'Upcoming'; // category to delete
$taxonomy = 'category';
// fetch category ID (amongst other data) of 'Upcoming':
$term = get_term_by('name',$old_name, $taxonomy);
// fetch all posts in 'Upcoming' category:
$objects = get_objects_in_term($term->term_id,$taxonomy);
// the $objects array now contains the post IDs of all upcoming events
// now, let's loop through them to manipulate:
foreach($objects as $object) {
// get start date:
$key = 'start'; // the name of the custom field
$start = get_post_meta($object, $key, true); // start date
$todays_date = date('Y-m-d'); // get current date
// Assuming, your dates in the custom fields are formatted YYYY-MM-DD:
if ($start < $todays_date) {
// change category:
$new_name = 'Current';
wp_set_post_terms( $object, $new_name, $taxonomy, false );
}
}
?>
Few notes:
The above would have to be altered for the change from "Current" to "Past", obviously.
It can easily be adapted to include time as well.
The cronjobs should initiate shortly after midnight
$first_time has to be a UNIX timestamp
Check the wordpress function reference for more information on the wp functions used above