I see this question has been posted multiple times but all of the examples I've tried are not working.
I want to limit the search by keywords to only search for exact word not a phrase or mixed content, so if I search for cheese It need to be limited only for word cheese, right now it will return content with word cheeseburger also.
The part of the search query in my modified template query is right here:
if ( 'featured' === $args['orderby'] ) {
$query_args['orderby'] = [
'menu_order' => 'ASC',
'date' => 'DESC',
'ID' => 'DESC',
];
}
if ( 'rand_featured' === $args['orderby'] ) {
$query_args['orderby'] = [
'menu_order' => 'ASC',
'rand' => 'ASC',
];
}
$job_manager_keyword = sanitize_text_field( $args['search_keywords'] );
if ( ! empty( $job_manager_keyword ) && strlen( $job_manager_keyword ) >= apply_filters( 'job_manager_get_listings_keyword_length_threshold', 2 ) ) {
$query_args['s'] = $job_manager_keyword;
//add_filter( 'posts_search', 'get_job_listings_keyword_search' );
}
$query_args = apply_filters( 'job_manager_get_listings', $query_args, $args );
if ( empty( $query_args['meta_query'] ) ) {
unset( $query_args['meta_query'] );
}
if ( empty( $query_args['tax_query'] ) ) {
unset( $query_args['tax_query'] );
}
/** This filter is documented in wp-job-manager.php */
$query_args['lang'] = apply_filters( 'wpjm_lang', null );
// Filter args.
$query_args = apply_filters( 'get_job_listings_query_args', $query_args, $args );
do_action( 'before_get_job_listings', $query_args, $args );
I can see that $query_args['s'] is standard query for search keywords but some standard query modifications I've tried like this examples
https://wordpress.stackexchange.com/questions/177183/make-a-wp-query-search-match-exactly-the-search-term/17786
WordPress exact search query
Query for exact word search
And other examples too, none of them are working for me.
Anyone have an idea how i can modify it so it can search only for exact word in content?
Related
I'm trying to remove msisdn field from MO calls on TAP3.11, but it doesn't handle the needed.
I want to set a condition, if the Msisdn doesn't start with 962 then remove the element.
My background is only with python, this's the first time with perl. I use it because after searching I believe that only perl can handle TAP files.
# Will scan all the calls for MTC's.
foreach $key ( #{$struct->{'transferBatch'}->{'callEventDetails'} } ) {
foreach ( keys %{$key} ) {
if ( $_ eq "mobileOriginatedCall" )
{
if ( defined $key->{$_}->{'basicCallInformation'} )
{
if ( defined $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'} )
{
if ( defined $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'})
{
if ( defined $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'})
{
if ($key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'} =~ /^[962]/)
{
$key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'}=();
}
}
}
}
}
}
}
}
Try with:
...
if ($key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'} =~ /^(?!962)/)
{
delete $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'};
}
The changes:
For deleting a key, use delete
For a "not starting with" regex, use: ^(?!WHATEVER), for example ^(?!962)
I'm trying to find a regex pattern that only accepts email with a specific domain as follows.
z= [a-zA-Z0-9]
y= [a-zA-z]
(1) zzz.zzz#domain.y (eg: andrew.hugh#gmail.com, anne.dal#yahoo.ca)
(2) zzz.zzz#zzz.domain.y (eg: bryan.hawk#admin.msn.com, nick.deboer#info.school.edu)
Currently what I have so far is:
[.a-zA-z0-9]*#domain.[a-zA-z0-9]
Could anyone help me on this?
Here you are
for request no 1
^[a-zA-Z0-9]+#domain\.[a-zA-z]+$
for request no 2
^[a-zA-Z0-9]+#[a-zA-Z0-9]+\.domain\.[a-zA-z]+$
It might be a lot easier to make a JavaScript function out of this, instead of doing it with Regex. As you have said in the comments; you don't mind.
function matchesEmail( email ) {
var acceptedEmails = [ "msn.com", "school.edu" ];
for( key in acceptedEmails ) {
var acceptedEmailDomain = acceptedEmails[ key ];
if( email.split( "#" )[1].split(".").slice(-2).join( "." ) === acceptedEmailDomain ) {
return true;
}
}
return false;
};
console.log( matchesEmail( "jesse#ddd.com" ) );
I am building a web push WordPress plugin and I want to pass project number from form input field to manifest.json file
which is included in index.php as
<link rel="manifest" href="/manifest.json">
Disclaimer: I'm the author of this plugin.
Instead of building your own from scratch, you could contribute to the already existing https://github.com/mozilla/wp-web-push.
If you want to build your own, you can check the source of that plugin out to see how we have implemented it.
We've built a class to handle it: https://github.com/marco-c/wp-web-app-manifest-generator.
You cannot pass any param to the manifest.json. You must genarate it as a static file when the form is submitted.
Here's the code that we have used for the Pushpad plugin:
if (file_exists ( ABSPATH . 'manifest.json' )) {
$oldManifestJson = file_get_contents ( ABSPATH . 'manifest.json' );
} else {
$oldManifestJson = '{}';
}
$data = json_decode ( $oldManifestJson, true );
$data ['gcm_sender_id'] = $settings ['gcm_sender_id'];
$data ['gcm_user_visible_only'] = true;
$newManifestJson = json_encode ( $data );
if ( is_writable ( ABSPATH . 'manifest.json' ) || !file_exists ( ABSPATH . 'manifest.json' ) && is_writable ( ABSPATH ) ) {
file_put_contents ( ABSPATH . 'manifest.json', $newManifestJson );
} else {
// display an error
}
My Select function of my QueryManager:
/**
* Führt eine SELECT - Query durch
*
* #param $select = array( array(column, [...]), table, shortcut )
* $orderby = array(column, sorting-type)
* $where = array( array( column, value, type[or, and] ), [...] )
* $innerjoin = array( table, shortcut, condition )
* $pagination = array( page, limit )
*
* #return array $data
*/
public function select($select,$orderby, $where, $innerjoin, $pagination)
{
$qb = $this->conn->createQueryBuilder()
->select($select[0])
->from($select[1], $select[2])
;
if ($orderby) {
$qb->orderBy($orderby);
}
if ($where) {
foreach($where as $cond) {
$x = 0;
if ( key($cond) == 0 ) {
$qb
->where($cond[0] . ' = ?')
->setParameter($x,$cond[1]);
}
elseif ( $cond[2] == 'and' ) {
$qb
->andWhere($cond[0] . ' = ?')
->setParameter($x,$cond[1]);
}
elseif ( $cond[2] == 'and' ) {
$qb
->orWhere($cond[0] . ' = :' . $x)
->setParameter($x,$cond[1]);
}
$x++;
}
}
if ($innerjoin) {
$qb->join($select[2],$innerjoin);
}
$this->sql = $qb->getSQL();
$this->totalRowCount = count( $qb->execute() ) ;
if ($pagination) {
$max = $pagination[0] * $pagination[1];
$first = $max - $limit;
$qb
->setFirstResult($first)
->setMaxResults($max)
;
}
$stmt = $qb->execute();
return $stmt->fetchAll();
}
I don't know why, but in action, this function produces a select query without inserted values for the parameters:
/**
* Lädt einen User nach dessen Username
*
* #param $username
* #return User $user | null
*/
public function getUser($username)
{
if($data = $this->select(array('*','users','u'), null, array( array('username',$username) ), null,null)) {
return $user = $this->hydrate($data);
}
return null;
}
I didn't get a result, and the query is not setup correctly:
array(0) { }
SELECT * FROM users u WHERE username = ?
In my opinion the Builder doesn't supstitute my parameters with the provided values ...
I got the latest version of Doctrine DBAL (2.4) and this version should support this features!
Thanks for Help and Suggestions :)
I also had this Problem. I have readed here doctrine 2 querybuilder with set parameters not working that:
You cant bind parameters to QueryBuilder, only to Query
But im creating SQL conditions as collected AND & OR experssions in deep nested objects, and the toppest object creates the query object. So i cant create the query object before, i always return expression objects.
So i solved the problem with direct including the variable into the prepared variable's position.
$qb->where($cond[0] . '=' . $cond[1]);
And because i expect strings there i added hard coded quotes. This is not the desired way, but at the moment i dont know how to solve that in an other way with binding parameters to the QueryBuilder object.
$expr = $d_qb->expr()->between($t_c, "'" . $date_from . "'", "'" . $date_from . "'");
Other suggestions?
Following codes results:
$expr = $d_qb->expr()->between($t_c, ':from', ':to');
$d_qb->setParameter('from', 1);
$d_qb->setParameter('to', 1);
or
$expr = $d_qb->expr()->between($t_c, ':from', ':to');
$d_qb->setParameter(':from', 1);
$d_qb->setParameter(':to', 1);
Results:
e0_.created BETWEEN ? AND ?
New to Symfony2 and Doctrine2, i have a function in my entity repository to search entities after form submission. Input is array $get that contain form fields like $get['name'] = 'aname'.
My problem is that when i request with an id, or an id and a name, it's ok by with only a name, all my entities are matched because the query that has been build have no where clause.
Here is my code :
public function search(array $get, $flag = False){
/* Indexed column (used for fast and accurate table cardinality) */
$alias = 'd';
/* DB table to use */
$tableObjectName = 'mysiteMyBundle:DB';
$qb = $this->getEntityManager()
->getRepository($tableObjectName)
->createQueryBuilder($alias)
->select($alias.'.id');
$arr = array();
//Simple array, will grow after problem solved
$numericFields = array(
'id');
$textFields = array(
'name');
while($el = current($get)) {
$field = key($get);
if ( $field == '' or $field == Null or $el == '' or $el == Null ) {
next($get);
}
if ( in_array($field,$numericFields) ){
if ( is_numeric($el) ){
$arr[] = $qb->expr()->eq($alias.".".$field, $el);
}
} else {
if ( in_array($field,$textFields) ) {
$arr[] = $qb->expr()->like($alias.".".$field, $qb->expr()->literal('%'.$el.'%') );
}
}
next($get);
}
if(count($arr) > 0) $qb->andWhere(new Expr\Orx($arr));
else unset($arr);
$query = $qb->getQuery();
if($flag)
return $query;
else
return $query->getResult();
}
The query generated with only a name (ex "myname") input is :
SELECT d0_.id AS id0 FROM DB d0_
It should be:
SELECT d0_.id AS id0 FROM DB d0_ WHERE d0_.name LIKE '%myname%'
What's wrong with my code ?
Thanks !
I don't know if it's related, but do not use "OR" or "AND" operators, because they have a different meaning that the classic "&&" or "||". cf http://php.net/manual/en/language.operators.logical.php
So, first, replace "AND" by "&&", and "OR" by "||".
you should use the setParameter method
$query->where('id = :id')->setParameter('id', $id);