Skip to content

Instantly share code, notes, and snippets.

View elvismdev's full-sized avatar
🏴

Elvis Morales elvismdev

🏴
View GitHub Profile
@elvismdev
elvismdev / functions.php
Created July 27, 2018 10:33
WordPress: Remove parent dropdown selector from hierarchical taxonomy.
<?php
function remove_tax_parent_dropdown() {
$screen = get_current_screen();
if ( 'region' == $screen->taxonomy ) {
if ( 'edit-tags' == $screen->base ) {
$parent = "$('label[for=parent]').parent()";
} elseif ( 'term' == $screen->base ) {
$parent = "$('label[for=parent]').parent().parent()";
<?php
add_filter( 'facetwp_query_args', function( $query_args, $class ) {
$query_args['post__not_in'] = [ 239 ];
return $query_args;
}, 10, 2 );
@elvismdev
elvismdev / functions.php
Last active July 18, 2018 00:26
WordPress: Exclude the most recent post from the main query without braking pagination.
<?php
// ...
/**
* Tweak Archive pages queries.
* @param object $query
* @return object
*/
function tweak_archives( $query ) {
@elvismdev
elvismdev / services.yaml
Created February 22, 2018 18:13
Symfony parameters config key example
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
# My application specific parameters.
app.gpu_qty: # The number of GPU cards each mining rig has.
rukia: 12
zangetsu: 4
app.gpu_share: 3 # How many GPU cards the two rig shares to divide profits.
@elvismdev
elvismdev / functions.php
Created January 11, 2018 21:38
JS alert/confirmation pop-up before permanently erase all content items in the WordPress trash.
<?php
function trash_empty_confirmation() { ?>
<script type="text/javascript">
(function($) {
$('[id=delete_all]').click(function(e){
return confirm( "Are you sure you want to permanently erase all content items in the Trash ?" );
});
})( jQuery );
</script>
@elvismdev
elvismdev / single-author.php
Created October 19, 2017 04:40
Combine tax_query and meta_query in WP_Query()
<?php
/**
* This is a kind of rare combination of arguments for WP_Query(), needed in some very special cases.
* This is an already tested snippet code that works!
*/
// Bring post from the global context (if not present already).
global $post;
// Define the post_type's to query for.
$post_types = array( 'event', 'post', 'book' );
@elvismdev
elvismdev / addthis_layers_array.php
Last active August 21, 2017 04:43
WordPress AddThis plugin (v6+) - Output and control programmatically the AddThis floating sidebar with it's "Smart Layers API": https://www.addthis.com/academy/smart-layers-api/
<?php
/**
* Output an AddThis floating share sidebar to the left with selected services.
*
* Notice 'desktop' and 'mobile' parameters, they take a Boolean data type as value, meaning it can be used to
* allow a more dynamic control and display of the sharing sidebar.
*
* More options to play with can be found here in the docs: https://www.addthis.com/academy/smart-layers-api/
* Just notice to convert the JSON format in the examples to PHP's array() format
@elvismdev
elvismdev / addthis_share_array.php
Created August 16, 2017 08:26
WordPress AddThis plugin - Override URL and Title to share via addthis_share variable https://www.addthis.com/academy/the-addthis_share-variable/
<?php
add_filter( 'addthis_share_array', function ( $addthis_share ) {
$addthis_share['title'] = 'My custom title';
$addthis_share['url'] = 'http://example.com/my-custom-title';
return $addthis_share;
});
@elvismdev
elvismdev / acf_filter_choice.php
Last active August 11, 2017 21:30
WordPress ACF - Remove / override the choices for a radio, checkbox and select fields.
<?php
/**
* Removes custom style selector for non Administrator user roles.
* Uses acf/load_field filter https://www.advancedcustomfields.com/resources/acf-load_field/
*
* @param array $field
* @return array
*/
function acf_filter_radio_choices( $field ) {
@elvismdev
elvismdev / sum_total_orders_revenue.php
Last active November 3, 2021 10:35
SUM up all values from table column - Doctrine QueryBuilder.
<?php
// Sum all values from order_total column in completed orders, and return.
$qb = $em->createQueryBuilder();
$qb = $qb
->select( 'SUM(e.orderTotal) as totalRevenue' )
->from( '[Vendor]\[Package]\Entity\Orders', 'e' )
->where( $qb->expr()->andX(
$qb->expr()->eq( 'e.orderStatus', ':status' ),
// $qb->expr()->in( 'e.state', array( 'queued', 'confirmed' ) )