Skip to content

Instantly share code, notes, and snippets.

View Jerl92's full-sized avatar

Jérémie Langevin Jerl92

View GitHub Profile
@Jerl92
Jerl92 / array-javascript.js
Created April 14, 2024 02:56
How to check if a value exists in an array using Javascript?
<script type = 'text/javascript' >
//code to check if a value exists in an array using javascript for loop
var fruits_arr = ['Apple', 'Mango', 'Grapes', 'Orange', 'Fig', 'Cherry'];
function checkValue(value, arr) {
var status = 'Not exist';
for (var i = 0; i < arr.length; i++) {
var name = arr[i];
@Jerl92
Jerl92 / parameters-url.php
Created April 13, 2024 13:30
How to get parameters from a URL string in PHP?
<?php
// Initialize URL to the variable
$url = 'https://www.geeksforgeeks.org?name=Tonny';
// Use parse_url() function to parse the URL
// and return an associative array which
// contains its various components
$url_components = parse_url($url);
@Jerl92
Jerl92 / filter-taxonomies.php
Created April 13, 2024 06:46
filter by taxonomies in admin
<?php
////////////////////////////
//
// Filter Music admin colums
// by artist and genre
//
///////////////////////////
function filter_cars_by_taxonomies( $post_type, $which ) {
// Apply this only on a specific post type
@Jerl92
Jerl92 / admin-columns.php
Last active April 13, 2024 06:47
Music CPT custom admin columns
<?php
////////////////////////////
//
// my_edit_music_columns( $columns )
// Music CPT admin colums
//
///////////////////////////
function my_edit_music_columns( $columns ) {
@Jerl92
Jerl92 / attachment-image.php
Created April 13, 2024 05:29
Get All Images in Media Gallery
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => - 1,
);
$query_images = new WP_Query( $query_images_args );
$images = array();
@Jerl92
Jerl92 / orientationchange.js
Created April 4, 2024 05:51
jQuery orientationchange function
jQuery(window).on('orientationchange resize', function (event) {
if(jQuery("body").width()>768){ // Make sure to test that width... Just a suggestion here.
jQuery('#main_navigation').show();
}
});
@Jerl92
Jerl92 / each-loop.js
Created March 20, 2024 11:06
how-to-set-interval-1-by-1-in-each-loop-of-jquery
$(".display").each(function(i,ele){
setTimeout(function() {
console.log($(ele).text());
}, (i+1)*1000);
})
@Jerl92
Jerl92 / Tax_query_variable.php
Created February 19, 2024 05:29
Tax_query terms ID's using variable
<?php
$tax = array( 19, 18, 214, 226, 20 );
$query_args = array (
'post_type' => 'works',
'tax_query' => array(
array(
'taxonomy' => 'materials',
'field' => 'term_id',
@Jerl92
Jerl92 / taxonomy-id.php
Created February 19, 2024 05:29
Get taxonomy name from ID
<?php
$term = get_term(123); //Example term ID
$term->name; //gets term name
?>
@Jerl92
Jerl92 / custom-user-role.php
Created January 26, 2024 03:31
How to enable a custom post type to custom user role in WordPress
<?php
add_action('admin_init','rpt_add_role_caps',999);
/**
add teachers capability
*/
function rpt_add_role_caps() {
// Add the roles you'd like to administer the custom post types
$roles = array('rpt_teacher','editor','administrator');