How to write a wordpress query when there are multiple values in custom fieldOrder wordpress post by custom field value?Wordpress custom field searchWordpress query - Order by meta-field valuewordpress query post by a custom field that is post typeWordPress WP_Query: Display custom post type based on custom meta value, and also order on another custom meta valueHow to modify custom fields meta box in WordPressUpdating a Wordpress post not working with add_post_metatrying to retrive a post_type with custom fields and media queryRetrieve posts by custom field with WP-REST-API in JavascriptOptimising WordPress query speed by grouping metadata
Robbers: The Hidden OEIS Substring
Redefining hyperref in document referencing
As the Dungeon Master, how do I handle a player that insists on a specific class when I already know that choice will cause issues?
Won 50K! Now what should I do with it
Spectrum vs eigenvalues
Would letting a multiclass character rebuild their character to be single-classed be game-breaking?
Assistant professor does not collaborate with or cite fellow department members, despite them being experts on the topic
Back to the nineties!
How might the United Kingdom become a republic?
What is temperature on a quantum level?
Is this floating-point optimization allowed?
Too many spies!
How does one stock fund's charge of 1% more in operating expenses than another fund lower expected returns by 10%?
As a DM, how to avoid unconscious metagaming when dealing with a high AC character?
The monorail explodes before I can get on it
Can I play a first turn Simic Growth Chamber to have 3 mana available in the second turn?
Why would guns not work in the dungeon?
Was the Ford Model T black because of the speed black paint dries?
Cops: The Hidden OEIS Substring
What does `[$'rn']` mean?
How to check the quality of an audio sample?
Ambiguous sentences: How to tell when they need fixing?
Redirecting of hostname to full qualified domain name with HTTPS fails
Why is dry soil hydrophobic? Bad gardener paradox
How to write a wordpress query when there are multiple values in custom field
Order wordpress post by custom field value?Wordpress custom field searchWordpress query - Order by meta-field valuewordpress query post by a custom field that is post typeWordPress WP_Query: Display custom post type based on custom meta value, and also order on another custom meta valueHow to modify custom fields meta box in WordPressUpdating a Wordpress post not working with add_post_metatrying to retrive a post_type with custom fields and media queryRetrieve posts by custom field with WP-REST-API in JavascriptOptimising WordPress query speed by grouping metadata
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a wordpress custom post type with custom fields. Initially the requirement was every post has only one pin "Say example" 1001 and all posts with custom fields has 1001 needs to be retrieved. I used query args as
<?php
$args = array(
'post_type'=> array('sales'),
'posts_per_page' => -1,
'meta_key'=> 'pin',
'meta_value'=> $pin
);
query_posts( $args );
?>
Now I can have multiple zips in single custom field.
https://www.dropbox.com/s/pk53z23jbfj8p2t/zipcode.png?dl=0
How the query needs to be altered so if the entered zip matched any one of the item on the filed, post is displayed.
So for example the custom field has values 63001,63002,63003 and so on. So if user enters 63002 all the posts with 63002 in the custom field needs to be displayed.
wordpress advanced-custom-fields
add a comment |
I have a wordpress custom post type with custom fields. Initially the requirement was every post has only one pin "Say example" 1001 and all posts with custom fields has 1001 needs to be retrieved. I used query args as
<?php
$args = array(
'post_type'=> array('sales'),
'posts_per_page' => -1,
'meta_key'=> 'pin',
'meta_value'=> $pin
);
query_posts( $args );
?>
Now I can have multiple zips in single custom field.
https://www.dropbox.com/s/pk53z23jbfj8p2t/zipcode.png?dl=0
How the query needs to be altered so if the entered zip matched any one of the item on the filed, post is displayed.
So for example the custom field has values 63001,63002,63003 and so on. So if user enters 63002 all the posts with 63002 in the custom field needs to be displayed.
wordpress advanced-custom-fields
If you have code then please share for better understanding.
– Dhruv
Mar 26 at 5:34
add a comment |
I have a wordpress custom post type with custom fields. Initially the requirement was every post has only one pin "Say example" 1001 and all posts with custom fields has 1001 needs to be retrieved. I used query args as
<?php
$args = array(
'post_type'=> array('sales'),
'posts_per_page' => -1,
'meta_key'=> 'pin',
'meta_value'=> $pin
);
query_posts( $args );
?>
Now I can have multiple zips in single custom field.
https://www.dropbox.com/s/pk53z23jbfj8p2t/zipcode.png?dl=0
How the query needs to be altered so if the entered zip matched any one of the item on the filed, post is displayed.
So for example the custom field has values 63001,63002,63003 and so on. So if user enters 63002 all the posts with 63002 in the custom field needs to be displayed.
wordpress advanced-custom-fields
I have a wordpress custom post type with custom fields. Initially the requirement was every post has only one pin "Say example" 1001 and all posts with custom fields has 1001 needs to be retrieved. I used query args as
<?php
$args = array(
'post_type'=> array('sales'),
'posts_per_page' => -1,
'meta_key'=> 'pin',
'meta_value'=> $pin
);
query_posts( $args );
?>
Now I can have multiple zips in single custom field.
https://www.dropbox.com/s/pk53z23jbfj8p2t/zipcode.png?dl=0
How the query needs to be altered so if the entered zip matched any one of the item on the filed, post is displayed.
So for example the custom field has values 63001,63002,63003 and so on. So if user enters 63002 all the posts with 63002 in the custom field needs to be displayed.
wordpress advanced-custom-fields
wordpress advanced-custom-fields
asked Mar 26 at 5:27
RamRam
631 silver badge11 bronze badges
631 silver badge11 bronze badges
If you have code then please share for better understanding.
– Dhruv
Mar 26 at 5:34
add a comment |
If you have code then please share for better understanding.
– Dhruv
Mar 26 at 5:34
If you have code then please share for better understanding.
– Dhruv
Mar 26 at 5:34
If you have code then please share for better understanding.
– Dhruv
Mar 26 at 5:34
add a comment |
2 Answers
2
active
oldest
votes
Try below:
$args = array(
'post_type'=> array('sales'),
'posts_per_page' => -1,
'meta_query' => array( array(
'key'=> 'pin',
'value'=> ','.$pin.',',
'compare'=> 'LIKE'
) )
);
query_posts( $args );
hi @jayadip its working but returning only 1 result even there are multiple posts. I am debugging it. Do you have any idea of what the issue is. Thanks buddy for your help.
– Ram
Mar 26 at 7:50
It worked using 'value'=> '$pin'
– Ram
Mar 26 at 10:49
add a comment |
try update your post meta value in json type by json_encode and get that by json_decode
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350376%2fhow-to-write-a-wordpress-query-when-there-are-multiple-values-in-custom-field%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try below:
$args = array(
'post_type'=> array('sales'),
'posts_per_page' => -1,
'meta_query' => array( array(
'key'=> 'pin',
'value'=> ','.$pin.',',
'compare'=> 'LIKE'
) )
);
query_posts( $args );
hi @jayadip its working but returning only 1 result even there are multiple posts. I am debugging it. Do you have any idea of what the issue is. Thanks buddy for your help.
– Ram
Mar 26 at 7:50
It worked using 'value'=> '$pin'
– Ram
Mar 26 at 10:49
add a comment |
Try below:
$args = array(
'post_type'=> array('sales'),
'posts_per_page' => -1,
'meta_query' => array( array(
'key'=> 'pin',
'value'=> ','.$pin.',',
'compare'=> 'LIKE'
) )
);
query_posts( $args );
hi @jayadip its working but returning only 1 result even there are multiple posts. I am debugging it. Do you have any idea of what the issue is. Thanks buddy for your help.
– Ram
Mar 26 at 7:50
It worked using 'value'=> '$pin'
– Ram
Mar 26 at 10:49
add a comment |
Try below:
$args = array(
'post_type'=> array('sales'),
'posts_per_page' => -1,
'meta_query' => array( array(
'key'=> 'pin',
'value'=> ','.$pin.',',
'compare'=> 'LIKE'
) )
);
query_posts( $args );
Try below:
$args = array(
'post_type'=> array('sales'),
'posts_per_page' => -1,
'meta_query' => array( array(
'key'=> 'pin',
'value'=> ','.$pin.',',
'compare'=> 'LIKE'
) )
);
query_posts( $args );
answered Mar 26 at 7:27
Jaydip NimavatJaydip Nimavat
3454 silver badges18 bronze badges
3454 silver badges18 bronze badges
hi @jayadip its working but returning only 1 result even there are multiple posts. I am debugging it. Do you have any idea of what the issue is. Thanks buddy for your help.
– Ram
Mar 26 at 7:50
It worked using 'value'=> '$pin'
– Ram
Mar 26 at 10:49
add a comment |
hi @jayadip its working but returning only 1 result even there are multiple posts. I am debugging it. Do you have any idea of what the issue is. Thanks buddy for your help.
– Ram
Mar 26 at 7:50
It worked using 'value'=> '$pin'
– Ram
Mar 26 at 10:49
hi @jayadip its working but returning only 1 result even there are multiple posts. I am debugging it. Do you have any idea of what the issue is. Thanks buddy for your help.
– Ram
Mar 26 at 7:50
hi @jayadip its working but returning only 1 result even there are multiple posts. I am debugging it. Do you have any idea of what the issue is. Thanks buddy for your help.
– Ram
Mar 26 at 7:50
It worked using 'value'=> '$pin'
– Ram
Mar 26 at 10:49
It worked using 'value'=> '$pin'
– Ram
Mar 26 at 10:49
add a comment |
try update your post meta value in json type by json_encode and get that by json_decode
add a comment |
try update your post meta value in json type by json_encode and get that by json_decode
add a comment |
try update your post meta value in json type by json_encode and get that by json_decode
try update your post meta value in json type by json_encode and get that by json_decode
answered Mar 26 at 7:20
Iris NguyenIris Nguyen
84 bronze badges
84 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350376%2fhow-to-write-a-wordpress-query-when-there-are-multiple-values-in-custom-field%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you have code then please share for better understanding.
– Dhruv
Mar 26 at 5:34