Skip to content

Instantly share code, notes, and snippets.

View alaanasssar's full-sized avatar

Alaa nassar alaanasssar

View GitHub Profile
@alaanasssar
alaanasssar / alphabetizing-posts.php
Created May 3, 2018 14:54
sort posts alphabetically by list A-Z for WordPress
<?php
//devolum.com
// copy this code to functions.php to create query var 'sort'
// function add_query_vars_filter( $vars ){
// $vars[] = "sort";
// return $vars;
// }
@alaanasssar
alaanasssar / chage_query_for_posts.php
Last active March 13, 2018 23:19
Change query for WP posts easily.
<?php
add_filter( 'pre_get_posts', 'chage_query_for_posts' );
function chage_query_for_posts( $query ) {
if ( ! is_admin() && $query->is_main_query() ) { // this work for all wordpress posts, you can use is_category or is_page or any if case you need this function work for!
$query->set(
'posts_per_page' => 50,
'cache_results' => false
@alaanasssar
alaanasssar / Change query for WP posts easily.
Created March 13, 2018 23:15
chage_query_for_posts.php
<?php
add_filter( 'pre_get_posts', 'chage_query_for_posts' );
function chage_query_for_posts( $query ) {
if ( ! is_admin() && $query->is_main_query() ) { // this work for all wordpress posts, you can use is_category or is_page or any if case you need this function work for!
$query->set(
'posts_per_page' => 50,
'cache_results' => false
@alaanasssar
alaanasssar / post_on_publish.php
Created November 29, 2017 10:43
Run custom function after publish post on WordPress
<?php
function post_on_publish( $post_id ) {
if ( get_post_status($post_id) == 'publish'){ // I have some issues with posting none published the post so this will check if the post already published.
// your custom function here
}
}
add_action( 'draft_to_publish', 'post_on_publish' );
add_action( 'new_to_publish', 'post_on_publish' );
@alaanasssar
alaanasssar / Handle_firebase_over_100_requerst.php
Last active November 29, 2017 10:39
Handle firebase send request over 100 token by sent them 99 by 99 token.
<?php
// Handle firebase send the request over 100 token by sent them 99 by 99 token.
// just use this function with $tokens_array and $data and run your firebase
// firebase function here : https://gist.github.com/alaanasssar/3ccb64133a1891e36abbdcbec0c45d4f
function handle_firebase_fcm ($tokens_array , $data , $google_api_key){
$tokens_array = array_chunk($tokens_arr, 99);
foreach ($tokens_array as $tokens) {
Firebase_notifications_fcm($tokens, $data, $google_api_key)
@alaanasssar
alaanasssar / gist:0c0976d2474d994ba9d4fd109af26dbc
Created October 30, 2017 00:47 — forked from billerickson/gist:2047229
Improve performance of WP_Query
<?php
$args = array(
// Normal query goes here //
'no_found_rows' => true, // counts posts, remove if pagination required
'update_post_term_cache' => false, // grabs terms, remove if terms required (category, tag...)
'update_post_meta_cache' => false, // grabs post meta, remove if post meta required
);
@alaanasssar
alaanasssar / maintenance.php
Last active October 13, 2017 13:04
Custom Maintenance page for WordPress.
<?php
/* Upload this file to the root of your wp-content folder.
* Domain : maintenance
*
* For style the page - Don't forget to remove this comment.
*
* function _e( $text, $domain = 'default' ) {
* echo $text ;
* }
@alaanasssar
alaanasssar / firebase_notifications.php
Last active November 2, 2017 22:59
send notifications with firebase FCM
<?php
/* Firebase_notifications_fcm
* How to use
* To use the function you need to have ($tokens, $data , $google_api_key)
* $google_api_ke after create an app in firebase you need to find Google Api Key
* $tokens an Array with devices tokens
* $data an Array with the data you will send with ( title , message ) for example
*/