Skip to content

Instantly share code, notes, and snippets.

@khoand0000
khoand0000 / truncate-string-with-ellipsis.md
Created December 25, 2015 09:48
truncate string with ellipsis
@khoand0000
khoand0000 / css-naming-conventions.md
Last active December 25, 2015 09:05
css naming conventions

Main reference: http://thesassway.com/advanced/modular-css-naming-conventions. I don't like BEM because I like lowercase and dashed in css

  • Objects traditionally are nouns. They take the form of:
.noun {}            // examples: .button, .menu, .textbox, .header
  • Parent-Child relationships are also nouns:
.noun {}            // parent: .post
.noun-noun {} // child: .post-title
@khoand0000
khoand0000 / download-post-conditions-checklist.md
Created December 25, 2015 07:05
conditions of download/view post checklist
  • $post_id is existing or not
  • $user can see $post_id or not
    • $user is author
    • or

request

  • authenticate $user ($user is logged in or not)
  • authorize $user: $user can do it
@khoand0000
khoand0000 / common-query-parameters.md
Last active December 27, 2015 16:19
common wordpress functions

posts

get_posts([
            'meta_query' => [
            // 'relation' => 'AND', // Optional, defaults to "AND"

                [
                    'key' => '',
                    'value' => '', // array
 //'type' => 'CHAR', // 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'
@khoand0000
khoand0000 / wp_reset_postdata.md
Last active December 24, 2015 08:16
When using wp_reset_postdata()?
@khoand0000
khoand0000 / remove-space-between-inline-block-elements.md
Last active December 23, 2015 11:19
remove space between inline-block elements
@khoand0000
khoand0000 / foreach-piklist.md
Created December 19, 2015 03:26
foreach is not working in piklist

I want to generate 10 controls by piklist by foreach. But the code is not working

$values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
foreach ($values as $value) {
  
  piklist('field', array(
      'type' => 'text',
      //'field' => '_field',
 'label' => 'field',
@khoand0000
khoand0000 / update-conditions.php
Created December 19, 2015 03:22
update condition is not working with html control ref: https://piklist.com/user-guide/docs/field-parameters/conditions/
piklist('field', array(
'type' => 'select'
,'field' => 'master_field'
,'label' => 'Master field'
,'choices' => array(
'update_field' => 'Update'
,'no_update_field' => 'No update'
)
,'conditions' => array(
array(
@khoand0000
khoand0000 / set-checkbox-checked.js
Last active December 29, 2015 18:36
test input[type=check] is checked or not. Set checkbox checked. ref: http://api.jquery.com/prop/
$('#photo').prop('checked', true);
// note: using .attr() not effect
$('#photo').attr('checked', 'checked'); // not effect
@khoand0000
khoand0000 / prevent-closing-dropdown-when-clicking.md
Created December 15, 2015 17:25
Stop just one dropdown toggle from closing on click