Powered By Blogger
Showing posts with label wordpress. Show all posts
Showing posts with label wordpress. Show all posts

Monday, May 11, 2020

How to change your search query parameter from ‘s’ to something else

<?php


add_filter('init', function(){

global $wp;


$wp->add_query_var( 'search_query' );

$wp->remove_query_var( 's' );

} );



add_filter( 'request', function( $request ){

if ( isset( $_REQUEST['search_query'] ) ){

$request['s'] = $_REQUEST['search_query'];

}


return $request;

} );

Thursday, February 27, 2020

How to find user assigned how many site in multisite wordpress


  1. select * from wp_blogs
From the output of the command note down the blog_id you want the users of. For eg: say you are wanting the users of the site with blog_id = 2 , next run the following query.
  1. select * from wp_users u join wp_usermeta um on u.id=um.user_id where um.meta_key="wp_2_capabilities"

REF : https://stackoverflow.com/questions/27495552/how-to-get-users-who-belong-to-a-wordpress-multisite-blog-site-with-sql

Tuesday, January 8, 2019

Add default text in content when click add new post

// Add default content in Post Editor.
add_filter('default_content', 'my_editor_content', 10, 2);

function my_editor_content($content, $post) {
if($post->post_type == 'post') {
$content = "<br><br>";
                $content .= "<p>Test</p>";
            return $content;
}
}

Thursday, September 13, 2018

call api in same wordpress instance OR WordPress REST API Calls Internally

REF : https://wpscholar.com/blog/internal-wp-rest-api-calls/



$api_data = array(
'post' => $post
);

$request = new WP_REST_Request( 'POST', '/gic/v1/subscriber' );
$request->set_query_params( $api_data );
$response = rest_do_request( $request );
$server = rest_get_server();
$data = $server->response_to_data( $response, false );
$json = wp_json_encode( $data );

Friday, October 27, 2017

bulk delete media OR remove media in wordpress

DELETE FROM `wp_posts` WHERE `post_type` = "attachment";
DELETE FROM `wp_postmeta` WHERE `meta_key` = "_wp_attached_file";
DELETE FROM `wp_postmeta` WHERE `meta_key` = "_wp_attachment_metadata";

Tuesday, October 10, 2017

custom URL change OR Re-write URL OR slug change for buudypress default slug

https://buddypress.org/2009/05/customizable-slugs-in-buddypress/


It’s actually as simple as defining the slugs you want to use in your wp-config.php file. All the slugs for every built in component can be changed. Here’s a list of settings you can add (with some alternate slugs already set), that will change the slugs for each component:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
define ( 'BP_ACTIVITY_SLUG', 'streams' );
define ( 'BP_BLOGS_SLUG', 'journals' );
define ( 'BP_MEMBERS_SLUG', 'users' );
define ( 'BP_FRIENDS_SLUG', 'peeps' );
define ( 'BP_GROUPS_SLUG', 'gatherings' );
define ( 'BP_MESSAGES_SLUG', 'notes' );
define ( 'BP_WIRE_SLUG', 'pinboard' );
define ( 'BP_XPROFILE_SLUG', 'info' );
 
/* Some other non-component slugs */
define ( 'BP_REGISTER_SLUG', 'signup' );
define ( 'BP_ACTIVATION_SLUG', 'enable' );
define ( 'BP_SEARCH_SLUG', 'find' );
define ( 'BP_HOME_BLOG_SLUG', 'news' );