Drupal 8 Query to get similar blog post

Here we are going to fetch similar blog by blog node id, so inside .theme file
( in theme root folder) you can add below code and fetch similar blog by “field_blog_tags” field in drupal 8

Drupal 8 Query to get similar blog post

   $valuesTags=$variables['node']->get('field_blog_tags')->getValue();
  foreach($valuesTags as $key=>$value)
   {
   
   $smilarprd[]=$value['target_id'];
   }

   $nids = \Drupal::entityQuery('node')->condition('type', 'blog_post')->condition('field_blog_tags', $smilarprd,'IN')->condition('nid', $Nid, '!=')->range(0, 3)->execute();
  $RelatedBlog =  \Drupal\node\Entity\Node::loadMultiple($nids);
 
 $variables['RelatedBlog'] = $RelatedBlog;
  

what is the usage of python lambda functions

Lambda is a keyword used to create an functions without a name or in simple lambda is used to create an anonymous functions,lambda function has n number of argument with a single expression which is processed and returned the result.we know normally a function is defined in python using def statement followed by function name and argument after evaluating it should return the result to get the result value when function is called but lambda has no name and return statement

Syntax Lambda functon

lambda arguments : expression

Example

Tenpercentage= lambda x :x * 10/100  

#"x" is an argument and "x * 10/100" is an expression which got evaluated and returned.   

print(Tenpercentage(200))

print(Tenpercentage(450))

Output

python lambda functions

See above code in Normal functions syntax

def Tenpercentage(n):
  return n * 10/100

print(Tenpercentage(450))

common usage of python lambda functions

Lambda function perform well if we use lambda functions inside another function see example

See example

def currency_convert(currencyvalue):  
    return lambda x:x*currencyvalue;

Israelicurrency=currency_convert(3.48);  #find dollar to Israeli New Shekel

print(Israelicurrency(100));

print(Israelicurrency(900));


indiancurrency=currency_convert(71.57);  #Find dollar to INR

print(indiancurrency(100));

print(indiancurrency(900));

python lambda functions inside anothor function

host is not allowed to connect to this mysql server

one of the most conman error when connecting to MySQL server is “host is not allowed to connect to this MySQL server” this because of the user don’t have right privileges to connect to this MySQL server follow below steps to connection issue in MySQL

if you have full permission in MySQL

Open Mysq-> phpmyadmin

Go to User accounts section

Create a new user and give all the privilege as shown in the below image

host is not allowed to connect to this mysql server

if you have cpanel info

Go to MySQL® Databases section

Scroll down to Add New User section

host is not allowed to connect to this mysql server 2

After Scroll down to Add User To Database section

Select table and user and Add User To Database

Click all ALL PRIVILEGES and Make Changes

host is not allowed to connect to this mysql server 3

indentationerror unindent does not match any outer indentation level visual studio code

One of the main issue we are facing with python code run is indentationerror actully that is is the confusion between tab and space in vscode. In this article we are going to discuss about how to fix indentationerror unindent does not match any outer indentation level visual studio code

Press  CTRL +SHIFT + P 

Then Convert Indentation to Tabs

indentationerror unindent does not match any outer indentation level visual studio code