Skip to content

Instantly share code, notes, and snippets.

View sadrul's full-sized avatar

Sadrul sadrul

  • Salzburg, Austria
View GitHub Profile
@sadrul
sadrul / wp_search_page_query_change.php
Last active August 29, 2015 14:00
Wordpress search page query change
<?php
function advanced_search_query1($query) {
if ($query->is_search()) {
$query->set('post_type', array('product'));
return $query;
}
}
add_action('pre_get_posts', 'advanced_search_query1', 1000);
@sadrul
sadrul / Drupal pull live site images for local site use
Created September 15, 2014 09:58
Drupal pull live site images for local site use
To do this, need to write this line in .htaccess file -
RewriteRule ^(sites/default/files/.*) http://livesite.com/$1 [L]
@sadrul
sadrul / calculate_page_execution_time.php
Last active August 29, 2015 14:07
Calculate Execution time
<?php
function time_elapsed($secs){
$bit = array(
'y' => $secs / 31556926 % 12,
'w' => $secs / 604800 % 52,
'd' => $secs / 86400 % 7,
'h' => $secs / 3600 % 24,
'm' => $secs / 60 % 60,
's' => $secs % 60
);
@sadrul
sadrul / drupal_custom_breadcrumb.php
Last active August 29, 2015 14:08
custom breadcrumb
<?php
function custom_breadcrumb() {
= node_load(arg(1));
= ['breadcrumb'];
if (!empty()) {
if (!drupal_is_front_page() && !empty()) {
= filter_xss(menu_get_active_title(), array());
if (->type == 'family') {
[] = l(t('Family'), 'pregnant/choose-adoption-family');
@sadrul
sadrul / bbpress_forum_role.php
Last active August 29, 2015 14:26
BBpress forum role change in bulk
<?php
add_action( 'wp', array($this, 'change_existing_user_forum_role') );
function change_existing_user_forum_role(){
$args = array (
'role' => 'bbp_spectator',
);
$user_query = new WP_User_Query( $args );
if ( ! empty( $user_query->results ) ) {
@sadrul
sadrul / group_ids_by_meta_value.php
Last active July 22, 2018 15:48
groups query for loop using group meta
<?php
function get_group_ids_by_type($type){
$group_ids = array();
$meta_query = array(
array(
'key' => 'group_type',
'value' => $type,
'compare' => '='
)
);
@sadrul
sadrul / buddypress_user_last_activity_insert.php
Last active February 3, 2020 17:03
Buddypress user last activity insert
<?php
add_action( 'wp_head', 'record_user_last_activity' );
function record_user_last_activity(){
$get_users = get_users( array( 'fields' => array( 'ID' ) ) );
if(!empty($get_users)){
foreach($get_users as $single){
bp_update_user_last_activity($single->ID);
}
}
}
@sadrul
sadrul / wp_pagination.php
Last active April 20, 2017 06:24
Number pagination function works in bp pages
<?php
// need to pass $the_query
function batd_num_pagination($the_query){
$total_pages = $the_query->max_num_pages;
if ($total_pages > 1) {
$paged = batd_paged_query_var();
$current_page = max(1, $paged);
echo '<div class="pagination no-ajax batd-pag" id="pag-top">';