-
Notifications
You must be signed in to change notification settings - Fork 1
/
course-guide.html
2042 lines (1590 loc) · 78.3 KB
/
course-guide.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Course Guide - WordPress Developer</title>
<script src="../jquery-v3.5.1.js"></script>
<link rel="stylesheet" href="../jquery-ui-1.12.1/jquery-ui-1.12.1/jquery-ui.min.css">
<style>
body {
background-color: #333;
padding: 60px;
}
p {
color: #ddd;
}
.ui-accordion-header-active {
background-color: #aaa;
}
.ui-widget-content {
background-color: #444;
}
h5 {
color: aquamarine;
}
pre {
background-color: #555;
color: #ddd;
padding: 30px 10px;
}
span {
color:yellow;
font-size: 16px;
}
</style>
</head>
<body>
<div id="accordion" >
<h3> Security </h3>
<div>
<pre>
// to sanitize input fields - a php method
sanitize_text_field()
the esc_html() will take care the converting the text
within the inner parenthesis
now instead of as a value
dont worry about the escaping on get_search_query(false)
becuase daw ung esc_html() ung nag handle non
to handle the malicous code
esc_html( get_search_query(false) )
</pre>
</div>
<h3> Course Javascript </h3>
<div>
<pre>
<span>
// here. put your focus on this.searchField.focus()
// what it does is to add focus on search field
// when users click - explained at f14v58 - 620
// we use set timeout to let the page load before adding focus
</span>
openOverlay(){
this.searchOverlay.addClass('search-overlay--active');
$('body').addClass('body-no-scroll');
setTimeout( () => this.searchField.focus() ,301)
this.isOverlayOpen = true;
}
</pre>
</div>
<h3> Course Functions | WordPress Functions </h3>
<div>
<pre>
steps in creating Custom Post Type
- create on mu-plugins folder
- register it to .php file
- create single-[CPTname]
- copy the single- HTML file to reduce coding
- create condition to display on front-end
- addjust the filter
- create archive - for its unique content
-
</pre>
<h5>WordPress Functions</h5>
<pre>
wp_reset_postdata(); always put this at the end of the loop
while() - loop
the_title()
the_content()
get_the_ID()
wp_list_pages() - outputing the list of pages
get_pages - return the pages in memory. whaaaT???
get_the_title( wp_get_post_parent_id( get_the_ID() ) ) - this will work really nicely if this returns zero means the current page is the parent page
the_author_posts_link();
the_date();
the_time('n.j.y') - from the course
the_time('M') - big letter M - Month
the_time('d') - small letter d Day
the_category()
echo get_the_category_list(', ') - gives the category
echo paginate_links() - shows the pagination
the_archive_title(); - shows the title for, author, category, dates
the_archive_description() - gives the archive description of course!
wp_trim_words(get_the_content(), 10) - 1st arg is the content we want to limit - 2nd args is how many words
echo get_post_type_archive_link('event') - to get the permalink of the archive ?? whattt??
has_excerpt() - usually for ir condition
- will return a value of TRU if the current
post has a hand-crafted excerpt
get_post_type_archive_link('event') - give the correct CPT link
get_post_type() = can use in if condition - will return the current CPT
<h5> HUSAY THIS we can use or create as many of this as we want - </h5>
//f14v57 - 12:00 - you watch
// will let us output a little bit of JS data into source
// 1st arg - the name of the handle of our main JS file
// dapat daw match kung nasan ung main JS file - pero gamit lang ung name ng handle as argument
// 2nd arg - gawagawa ng variable name
// 3rd arg - an array of data that we want to be availabe in Javascript
wp_localize_script('main-university-js', 'universityData', array(
'root_url' => get_site_url()
) );
</pre>
<h5> Advance Custom Fields</h5>
<pre>
get_post_field() - for pick date - if get_field() doesnt work
$eventDate = new DateTime( get_post_field('event_date')) ;
echo $eventDate->format('M');
is_page('past-events') - kung nasa page tayo ng post type
is_admin() - will return true if we are on the admin portion of the website.
!is_admin() - will return true if we are on the front-end portion of the website.
$pageBannerImage = get_field('page_banner_background_image'); echo $pageBannerImage['url']
</pre>
<h5> Hooks </h5>
<pre>
// true to allow crop - false no crop
add_image_size('nickname','wide', 'tall', TRUE or FALSE)
</pre>
</div>
<h3>Hierarchy WordPress</h3>
<div>
<h5>Functions</h5>
<pre>
every custom post type has - single-[CTPname], archive-[CPTname]
index.php - universal fallback - the blog page can use this
- pang blog talga ata sya? video 30 still using this as a blog page
single.php - is when we click to link from a post.
- the single.php page will be use and show content
- eto ung pag click ng blog ( index.php ) pupunta dito.
- only uses the single.php for individual posts for individual pages ( ung reading kana ng blog)
single-[CUSTOM POST TYPE] - dito pupunta ung post ng custom post type
page.php - will serve all the pages
archive.php - will serve the - author page, category page, date page
archive-[CUSTOM POST TYPE] - this will serve as the archive page for CPT
- just copy the HTML of archive.php -
front-page.php - is for home page
</pre>
</div>
<h3>Plugins installed during course</h3>
<div>
<pre>
Advance Custom Field - Elliot Condon
Regenerate Thumbnails - By Alex Mills (Viper007Bond)
</pre>
</div>
<h3 class="table-tab">F3v1 - Create Theme style.css</h3>
<div>
<h5>create theme</h5>
<p>
go to style.css, write at the top
</p>
<pre>
Theme Name: your theme name
Author: your name
Version: theme version 1.0
name the thumbnail image screenshot
</pre>
</div>
<h3>To note when creating relationship on post_type</h3>
<div>
<pre>
<h5>
remember that WordPress only Query 10 posts at a time
</h5>
</pre>
<pre>
if the Advance Custom Field variable that we create is already under the
post_type -- there is no need to create a filter -- becoz we can just call it there.
gets moba ?
</pre>
<h5> To loop inside foreach</h5>
<pre>
$relatedCampus = get_field('related_campuses');
if($relatedCampus){
echo '[h2 class="headline headline--medium" >' . get_the_title() . ' is Available at these Campuses: [/h2]';
foreach($relatedCampus as $campus ){ ?>
li
a href="[?php echo get_the_permalink($campus)?]" [?php echo get_the_title($campus) ?]
/a
/li
[?php
}
}
</pre>
</div>
<h3>f410 - WordPress Loops</h3>
<div>
<h5>Functions</h5>
<pre>
while(have_posts()){
the_post()
href="the_permalink" the_title()
the_content()
}
</pre>
<h5>
single.php
</h5>
<pre>
</pre>
</div>
<h3>f411 - header and footer </h3>
<div>
<pre>
function university_files(){
//1st argument - chosen name for function
//2nd argument - url
wp_enqueue_style('university_main_styles', get_stylesheet_uri() );
}
//1st argument - what type of instructions
//2nd argument - name of the function
add_action('wp_enqueue_scripts','university_files');
</pre>
</div>
<h3>f412 - - HTML to WordPress </h3>
<div>
<h5> added aditional CSS to functions and copying static HTML to wordpress</h5>
<pre>
//1st argument - chosen name for function
//2nd argument - url
//3rd argument - WordPress wants to know if this script depends on in other script
//if it depending on other dependencies? - no so NULL
// 4th in CSS - microtime() - to remove caching in css.
wp_enqueue_style('university_main_styles', get_stylesheet_uri(), NULL, microtime() );
wp_enqueue_style('custom-google-font', '//fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i|Roboto:100,300,400,400i,700,700i' );
wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' );
</pre>
<pre>
//3rd argument - WordPress wants to know if this script depends on in other script
//if it depending on other dependencies? - no so NULL
//4th argument - What is the version but in local dev we need microtime.
//microtime - to remove caching of css and js
//5th argument - if we want to load it before closing body tag. Yes (True) or No (False)
// TRUE - going to the bottom of body tag
wp_enqueue_script('main-university-js', get_theme_file_uri('/js/scripts-bundled.js'), NULL, microtime() , TRUE );
</pre>
<pre>
//1st argument - chosen name for function
//2nd argument - url
//3rd argument - WordPress wants to know if this script depends on in other script
//if it depending on other dependencies? - no so NULL
// 4th in CSS - microtime() - to remove caching in css.
wp_enqueue_style('university_main_styles', get_stylesheet_uri(), NULL, microtime() );
</pre>
</div>
<h3>f413 - Prevent Caching CSS and JS Dev </h3>
<div>
<h5> short vid</h5>
<pre>
//microtime - to remove caching of css and js
wp_enqueue_script('main-university-js', get_theme_file_uri('/js/scripts-bundled.js'), NULL, microtime() , TRUE );
</pre>
</div>
<h3>f5v14 - integrate interior page </h3>
<div>
<h5> adding theme features </h5>
<pre>
function university_features(){
//theme functions
add_theme_support('title-tag');
}
//1st argument - wordpress event
//2nd args - function - a name of function we will invent
add_action('after_setup_theme', 'university_features')
</pre>
</div>
<h3>f5v15 - Parent and Children Pages | with [if] statement </h3>
<div>
<h5> Parent and Child Theme relation </h5>
<pre>
we create OUR HISTORY page. then on page attribute ( right side panel )
instead of no paren we choose ABOUT US
Same in creating OUR GOAL PAGE
</pre>
<h5> Get the parent ID </h5>
<pre>
echo get_the_ID() - will give us the page ID
wp_get_post_parent_id(get_the_ID()) - it will give us the ID of the parent page
- or we want to know if the current page has a parent page - and give the parenthesis an argument of the page ID
- it will give us [0] zero, if it has no parent page.
- now if its has a parent page i will give us integer any value.
the_title() - will give you the current page title
get_the_title(get_the_ID()) - allows us to pass an ID number the title for that post instead of just the current post that you've looped through.
</pre>
<h5> echo or not echo </h5>
<pre>
all wp function starts with [get]
will not echo the value instead use the [echo]
to output it out
</pre>
</div>
<h3> f5v17 - Menu of Child Page Links | hirap dito men pero nagets ko | </h3>
<div>
<h5>Angaling dito .</h5>
<pre>
get_the_title( wp_get_post_parent_id( get_the_ID() ) )
- this will work really nicely if this returns zero means the current page is the parent page
</pre>
<pre>
$testArray = get_pages( array(
'child_of' => get_the_ID() //-- if the current page has children this function wil return a collection of any and all children
- on the other hand if the pages doesnt have any children this function won't return anything - it will return NULL of False
))
-
</pre>
<h5> Pusang gala - sana maalala ko nog?</h5>
<pre>
$parentPageID = wp_get_post_parent_id( get_the_ID() );
if ( $parentPageID )
if( $parentPageID ){
$findChildrenOf = $parentPageID;
} else {
$findChildrenOf = get_the_ID();
}
wp_list_pages( array(
//title_li is empty
//child_of - numerical ID of a certain page or post
//sort_column => 'menu_order' we can choose the order output of link -
// ^ you can control this on right panel and choose the order number
'title_li' => NULL,
'child_of' => $findChildrenOf,
'sort_column' => 'menu_order'
))
</pre>
</div>
<h3> f5v18 - Quick Edits</h3>
<div>
<pre>
language-attributes()
charset=bloginfo('charset')
body_class()
</pre>
</div>
<h3>f5v19 - Navigation Menus </h3>
<div>
<h5>Dynamic</h5>
<pre>
register_nav_menu('footerMenuLocationOne', 'Footer Menu Location One');
wp_nav_menu(array(
'theme_location' => 'footerMenuLocationOne'
</pre>
<h5> Custom</h5>
<pre>
If we are on the current page the menu link will lit
[?php if( is_page('about-us') or wp_get_post_parent_id(0) == 10) echo 'class="current-menu-item"' ?] >[a href="[?php echo site_url('/about-us') ?]" About Us[/a]
</pre>
</div>
<h3>f6v22 - Blog Archives | ung author and category page </h3>
<div>
<h5>Author and Category the old way </h5>
<pre>
if( is_category() ){
single_cat_title();
}
if( is_author() ){
echo 'Posts by : '; the_author();
}
</pre>
<h5> Author, Category, Dates - Dynamic</h5>
<pre>
the_archive_title() - gives the title of author, category, dates
the_archive_description()
</pre>
</div>
<h3>f623 - Custom Queries | Finally </h3>
<div>
<h5> in f15v63 - we created a new way how to create this outside this front-end.php file</h5>
<pre>
$homepagePosts = new WP_Query(array(
'posts_per_page' => 2
));
while( $homepagePosts->have_posts() ){
$homepagePosts->the_post();
</pre>
<pre>
wp_trim_words(get_the_content(), 10)
1st args- is what we want to trim
2nd args how may words we display
</pre>
<h5> Important </h5>
<pre>
always put this at the end of the loop
wp_reset_postdata();
this will reset the different WordPress Data and global variables back
to the state that it was in when it made its default automatic query based on the
current URL right before we came along and made a custom query
calling this function is not 100% necessary specially if youre towards
the bottom of the template file, but its a really good habit to get into
</pre>
</div>
<h3>f726 - </h3>
<div></div>
<h3>f7v27 and 28 - GULP WATCH Auto loading fronpage CSS and JS</h3>
<div></div>
<h3> f9v29 - Custom Post Types </h3>
<div>
<h5>Put it in /wp-content/ create mu-plugins folder then create php file</h5>
<pre>
function university_post_types(){
//public - this will make visible to editors and viewers of the website
//labels -> name -> the name on side panel
//has_archive -> true - to tell WP to create an archive page for this CPT
//'rewrite' => array('slug' => 'events') -- will change the URL link from singular to plural - ['slug' => 'events'] we can actually invent the word 'events' to pizza or anything!
register_post_type('event', array(
'rewrite' => array('slug' => 'events'),
'has_archive' => true,
'public' => true,
'labels' => array(
'name' => 'Events',
'add_new_item' => 'Add New Event',
'edit_item' => 'Edit Event',
'all_items' => 'All Events',
'singular_name' => 'Event'
),
'menu_icon' => 'dashicons-calendar'
));
}
// 1st args a hook
// name of a function
add_action('init', 'university_post_types');
</pre>
<pre>
So if ever the theme file deactivated the post type will still be there.
</pre>
</div>
<h3> f9v30 - Displaying Custom Post Type </h3>
<div>
<pre>
gumawa ng single-[Custom-Post-Type-Name-HERE] - para dun sa mga post
gumawa ng achive-[Custom-Post-Type-Name-HERE] - para dun sa pinaka page ng Custom-Post-Type-Name-HERE
ginamit ung HTML ng single.php sa single-[Custom-Post-Type-Name-HERE]
ginamit ung HTML ng archive.php sa archive-[Custom-Post-Type-Name-HERE]
inedit lang ng unti
nirefresh ung permalink para marefresh ung site URLS
</pre>
<pre>
function university_post_types(){
//public - this will make visible to editors and viewers of the website
//labels -> name -> the name on side panel
//has_archive -> true - to tell WP to create an archive page for this CPT
//'rewrite' => array('slug' => 'events') -- will change the URL link from singular to plural - ['slug' => 'events'] we can actually invent the word 'events' to pizza or anything!
register_post_type('event', array(
'rewrite' => array('slug' => 'events'),
'has_archive' => true,
'public' => true,
'labels' => array(
'name' => 'Events',
'add_new_item' => 'Add New Event',
'edit_item' => 'Edit Event',
'all_items' => 'All Events',
'singular_name' => 'Event'
),
'menu_icon' => 'dashicons-calendar'
));
}
// 1st args a hook
// name of a function
add_action('init', 'university_post_types');
</pre>
</div>
<h3>f9v31 - Quick edit - wp_trim_words() + the_excerpt() </h3>
<div>
<h5> Combination </h5>
<pre>
if( has_excerpt() ) {
echo get_the_excerpt();
} else {
echo wp_trim_words(get_the_content(), 18 );
}
</pre>
<pre>
get_post_type_archive_link('event') - give the correct CPT link
get_post_type() = can use in if condition - will return the current CPT
</pre>
</div>
<h3>f9v32 - Advanced Custom Fields </h3>
<div>
<pre>
We create custom field then ouput it in fron-end
get_post_field()
</pre>
</div>
<h3>f9v33 - Advance Custom Fields - ordering | sorting</h3>
<div>
<h5>1st introduction of the meta_queries</h5>
<pre>
//post_per_page - kung ilan lilitaw dun sa fron-end
//post_type - kung anong post type
// orderby - post_date - the date that the post was created or published
// ^ - value [post_date] is the default value
//^ value [title] - will be alphabetically
//^ orderby->rand - post will be random
//^ orderby->meta_value_num - it need the meta_key 1st - then the value means that the orderby will be base on any value of Post Type.
// meta_key-event_date - the ACF variabe
// 'posts_per_page' => -1, -1 meaning the WP will give all the posts
// order -> DESC - post will be descending
// order -> ASC - post will be Ascending
// meta_query - array->
// ^key - the ACF
// ^compare - the condition
// ^value - here is date $today
$today = date('Ymd');
$eventPostType = new WP_Query(array(
'posts_per_page' => 2,
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $today,
'type' => 'numeric'
)
)
</pre>
</div>
<h3>f934 - Manipulating Defaul URL Based Queries</h3>
<div>
<h5> and nagyare - nag karoon ng pagination ung posts pages - ung post type and blog page . without using pagination() function</h5>
<h5> kahit ung sa backend sa WP panel naging isa nalang ung post! which is 3 un! </h5>
<h5>very powerful!</h5>
<h5> 1st explain </h5>
<pre>
function university_adjust_queries($query){
// set has 2 args
//1st args is the name of a query parameter that we want to change
// the value that we want to use
$query->set('posts_per_page', '1');
}
//pre_get_posts - ryt before we get the post with the query
// its going to give a reference to the wordpress query object
add_action('pre_get_posts', 'university_adjust_queries');
</pre>
<h5>2nd explain</h5>
<pre>
function university_adjust_queries($query){
// set has 2 args
//1st args is the name of a query parameter that we want to change
// the value that we want to use
//$query->set('posts_per_page', '1');
//if not in the admin -
// kung nasa post type archive event daw tayo
//$query so if daw the $query that is being passed into our function
// the $query then we can look for a method named is_main_query()
// so this way daw we cannot accidentally manipulate a custom query
// $query->is_main_query() - will only evaluate to true if
// the query in question is the default URL based query
//Always perform 1 more check
if ( !is_admin() AND is_post_type_archive('event') AND $query->is_main_query() ) {
$query->set('posts_per_page', '1');
}
}
//pre_get_posts - ryt before we get the post with the query
// its going to give a reference to the wordpress query object
add_action('pre_get_posts', 'university_adjust_queries');
</pre>
<h5>final explain | para imbes na gwin dun sa pinaka file for example index.php, dito nalang sya sa functions.php gagawin, para mas malinis. so ganto ang pag gawa ng custom post type sa function.php</h5>
<pre>
function university_adjust_queries($query){
// set has 2 args
//1st args is the name of a query parameter that we want to change
// the value that we want to use
//$query->set('posts_per_page', '1');
//if not in the admin -
// kung nasa post type archive event daw tayo
//$query so if daw the $query that is being passed into our function
// the $query then we can look for a method named is_main_query()
// so this way daw we cannot accidentally manipulate a custom query
// $query->is_main_query() - will only evaluate to true if
// the query in question is the default URL based query
//Always perform 1 more check
if ( !is_admin() AND is_post_type_archive('event') AND $query->is_main_query() ) {
// this query is to not show the past events. VERY POWERFUL!
$today = date('Ymd');
$query->set('meta_key', 'event_date');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
$query->set('meta_query', array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $today,
'type' => 'numeric'
)
)
);
}
}
//pre_get_posts - ryt before we get the post with the query
// its going to give a reference to the wordpress query object
add_action('pre_get_posts', 'university_adjust_queries');
</pre>
</div>
<h3>f9v35 - Past Events Page - Custom Query Pagination </h3>
<div>
<pre>
echo paginate_links() will display the default URL base queries, so if we want to display custom post type pagination we need to create function like below.
</pre>
<pre>
echo paginate_links(array(
'total' => $pastEvents->max_num_pages
));
</pre>
</div>
<h3>f9v36 - Creating Programs Post Type | creating relationship between content</h3>
<div>
<pre>
//the 3rd condition - if only the $query in question can look inside its main
//query -- so that way we dont manipulate any secondary custom quries,
// we only want to manipulate the main default URL based query
// this is the safest condition check
if( !is_admin() AND is_post_type_archive('program') AND $query->is_main_query() ) {
$query->set('orderby','title');
$query->set('order','ASC');
$query->set('post_per_page', 5);
}
</pre>
<h5>Creating relationship between Program and Event</h5>
<pre>
Gumawa kami sa Advance Custom Fields - ang notable na gina is -
ung filter by post type is [Program]
- tapos ung dun sa Location na sa baba - ung show this field group if - is equal - Event
<h5> And nangyari - nag karon ng relationship form dun sa Program post type </h5>
<pre>
next video - displaying to fron-end
</pre>
</pre>
</div>
<h3>f937 - Displaying Relationship to front-end</h3>
<div>
<h5>
kapag my foreach - we need to use echo get_the_whatever, para gumana
</h5>
<pre>
$relatedPrograms = get_field('related_programs');
foreach($relatedPrograms as $program ){ ?>
href="php echo get_the_permalink($program) "> php echo get_the_title();
</pre>
<h5>In single-programs.php - we create 2 filters </h5>
<pre>
//post_per_page - kung ilan lilitaw dun sa fron-end
//post_type - kung anong post type
// orderby - post_date - the date that the post was created or published
// ^ - value [post_date] is the default value
//^ value [title] - will be alphabetically
//^ orderby->rand - post will be random
//^ orderby->meta_value_num - it need the meta_key 1st - then the value means that the orderby will be base on any value of Post Type.
// meta_key-event_date - the ACF variabe
// 'posts_per_page' => -1, -1 meaning the WP will give all the posts
// order -> DESC - post will be descending
// order -> ASC - post will be Ascending
// meta_query - array->
// ^key - the ACF
// ^compare - the condition
// ^value - here is date $today
$today = date('Ymd');
$eventPostType = new WP_Query(array(
'posts_per_page' => 2,
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $today,
'type' => 'numeric'
),
<h5>this is the 2nd filter </h5>
--------------------------------------------
array(
'key' => 'related_programs',
'compare' => 'LIKE',
'value' => '"'. get_the_ID() .'"'
)
--------------------------------------------
)
));
</pre>
<h5>
Flashback - its from folder 12 video 48
a broader explain
</h5>
<pre>
//post_per_page - kung ilan lilitaw dun sa fron-end
// 'posts_per_page' => -1, -1 meaning the WP will give all the
//post_type - kung anong post type
// orderby - post_date - the date that the post was created or published
// ^ - value [post_date] is the default value
//^ value [title] - will be alphabetically
//^ orderby->rand - post will be random
//^ orderby->meta_value_num - it need the meta_key 1st - then the value means that the orderby will be base on any value of Post Type.
// meta_key-event_date - the ACF variabe posts
// order -> DESC - post will be descending
// order -> ASC - post will be Ascending
// meta_query is parang filter
// so its looking for a KEY - which is the POST TYPE
// meta_query - array->
// ^key - the ACF
// ^compare - the condition
// ^value - here is date $today
// to sum up on meta_query =
// ^ the post type program is looking for a
// meta_query that has a KEY 'related_campus'
// that LIKE - means exactly
// thas has a VALUE of the current campus that we are viewing
//
// we are creating this new query to give us any program post
// that has relation on related_campuse post type
$relatedPrograms = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'program',
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'related_campuses',
'compare' => 'LIKE',
'value' => '"'. get_the_ID() .'"'
)
)
));
</pre>
</div>
<h3> f9v38 - Quick Edits </h3>
<div>
<h5> single-program.php </h5>
<pre>
Nilagyan lang ng IF condition.
</pre>
<pre>
/* IF CONDITION */
/* para hindi mag appear ung UPCOMING EVENTS na title tag
tapos sa loob nun ung content na relation nun sa event?? gets moba ? ano kaya pa?
*/
if($eventPostType->have_posts()) {
</pre>
</div>
<h3>f10v39 - Professor Post Type</h3>
<div>
<pre>
$relatedProfessor = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'professor',
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'related_programs',
'compare' => 'LIKE',
'value' => '"'. get_the_ID() .'"'
)
)
));
</pre>
<pre>
wp_reset_postdata();
</pre>
video stop at 15:40
</div>
<h3>f1040 - Featured Image (post thumbnails)</h3>
<div>
<pre>
//1st arg nickname for the image size - any name
// image wide - 400 - tall - 260
// 3rd image - if we want to crop - FALSE
// if we want the image to be exactly this wide
// and exactly this tall, we need to give it TRUE
add_image_size('professorLandscape', 400, 260, true);
add_image_size('professorPortrait', 480, 650, true);
go to functions - add_theme_support('post-thumbnails');
</pre>
<pre>
go to mu-plugins folder - add in the supports array
register_post_type('professor', array(
'supports' => array('title', 'editor', 'thumbnail'),
'public' => true,
'labels' => array(
'name' => 'Professor',
'add_new_item' => 'Add New Professor',
'edit_item' => 'Edit Professor',
'all_items' => 'All Professor',
'singular_name' => 'Professor'
),
'menu_icon' => 'dashicons-welcome-learn-more'