Skip to content

Instantly share code, notes, and snippets.

View LeanSeverino1022's full-sized avatar

Leandro Severino LeanSeverino1022

View GitHub Profile
@LeanSeverino1022
LeanSeverino1022 / notes.md
Last active April 5, 2020 08:24
[WP_Query Arguments] #wordpress
@LeanSeverino1022
LeanSeverino1022 / test.php
Created April 4, 2020 15:22
Ordering by custom field
//checkout unlocking power with code sec 8- Ordering (Sorting) Custom Queries
<?php
$today = date('Ymd');
$homepageEvents = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' =>'meta_value_num',
'order' => 'ASC',
@LeanSeverino1022
LeanSeverino1022 / snippet.php
Last active November 18, 2024 16:16
[Display post types] #wordpress
//Just copy paste the code in any php file and see the result
//Display ALL post types
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
echo '<p>' . $post_type . '</p>';
}
@LeanSeverino1022
LeanSeverino1022 / readme.md
Created April 2, 2020 03:03
[SQL] good resources from falviocopes so I just dump it #dump #sql
@LeanSeverino1022
LeanSeverino1022 / readme.md
Last active April 28, 2021 12:29
[_Just enough wordpress] just enough stuff I need for now #wordpress
@LeanSeverino1022
LeanSeverino1022 / readme.md
Last active April 5, 2020 04:19
[THe Famous Loop in WP] #wordpress

THe Famous Loop in WP - heart and soul of WP

page, index, and single php files all have one very important thing in common and that is they all use the famous loop

  while (have_posts()) {
      the_permalink()
      the_post()
      the_title()
 the_content()
@LeanSeverino1022
LeanSeverino1022 / readme.md
Last active April 5, 2020 04:21
[Enqueue scripts and styles ] #wordpress

Add custom CSS / JS file in theme

add_action( 'wp_enqueue_scripts', 'custom_site_files');

function custom_site_files() {
	wp_enqueue_script('main-university-js', get_theme_file_uri('/js/scripts-bundled.js'))
    wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
    wp_enqueue_style( 'another-style', get_template_directory_uri() . '/css/reset.css');
 
@LeanSeverino1022
LeanSeverino1022 / test.md
Last active March 18, 2020 17:32
[Multiple ajax calls in an array and handle callback when all are completed] create an array of promises so that once all promises are resolved you can run your callback #jQuery #cheatsheet #dump

Wait until all jQuery Ajax requests are done and then do something...

Example on when to use: I want that after all promises are resolved, do something. For example every ajax request adds the ajax response data in an array. I want to make sure all data has been added before doing something else.

#1

	// You can create an array of promises so that once all promises are resolved you can run your all done code.
    
  var promises = []
@LeanSeverino1022
LeanSeverino1022 / debounce.js
Last active March 30, 2021 03:40
debounce and throttle #vanillajs
const debounce = (func, delay) => {
let debounceTimer //to maintain internal reference of timeout so we can clear it
return function () {
const context = this
const args = arguments
clearTimeout(debounceTimer)
debounceTimer
= setTimeout(() => func.apply(context, args), delay)
}
}