I'm trying to sort a query of product custom post type, ordering by the product weight (ASC - from lightest to heaviest). The product weight is entered in a Advanced Custom Fields "field" on the product edit screen.
The query is working fine, except for when the number contains a comma (ex 1,000). It will put a product with a weight of 1,000 at the top of the list (first). So is somehow not looking at the number past the comma, so views it as 1, not 1,000.
Fortunately, I was able to convince my client to leave out the commas and are using the php number_format() to display the comma on the front end.
However, I don't like relying on my client to remember to exclude the comma for the sorting to work correctly.
Is there a way to have WP Query properly sort number values with commas in them? Maybe with an action or filter to remove the comma before saving in the DB and then adding it back once it's displayed in a template file? I really don't have much experience with actions and filters in WordPress yet.
Thanks in advance.
Related
The following WP-CLI command works great for getting all posts in a specific category, but I need to restrict it further to just those with an ID number less than a specific number. This is because I just exported a bunch of posts below a specific ID number and now need to remove them from the original site.
wp post list --cat=34 --format=ids
What must I add to the above so that the list only includes posts with ID<16163
I thought --post__in might do the trick but this only seems to list specific posts if you list their ID numbers separated by a comma. The description from Wordpress looks like it takes a range but it seems like a specific list.
Update: With the help of the answerer below I figured out how to do this. Basically I used a WP Query to get users and their user metadata and I sorted and placed the data in a for each loop in a table.
I'm new to PHP and I need some help. Basically I want to create a leaderboard with different user data. I want to display it in an html table.
This is kinda what i want:
Username GamiPress Points Time since last login
And I want the table to be populated with these data amongst others automatically. I want two versions one that is sorted with the 15 users who have the most points and one that sorts on the 15 users that logged in last.
Can someone point me to the right place on how I can best implement this?
I basically want to create the GamiPress Leaderboard add-on that I, unfortunately, can't afford, but with some extra fields.
There are multiple steps to do if you want to achieve this:
1) Add meta field to your users, so you can store the points. For example you can use "Advanced Custom Fields" plugin for this.
2) Write a function for adding points to this field. Define when this function will be fired.
3) Query the users ordered by that meta value and display it (get_users($args) might be useful).
4) For the Last-Login value you can use a plugin (google Wordpress Last Login) and write another Query and order results by that meta field. You can also write this by your own, here is a link I found: https://www.wpbeginner.com/plugins/how-to-show-users-last-login-date-in-wordpress/
I don't know if this is what you were looking for.
Or did you want to see an example code how you use a wp query and display data in html table?
I'm trying to add some filters to request for news in bing api but currently I don't get any effects of doing this ( for example filter for news from current month).
I'm trying to this with : https://api.cognitive.microsoft.com/bing/v5.0/news/search?freshness=month&?category=business , and replacing some filters here but I always getting the same result.
Currently i want to add three filters : freshness, category and language for news from current day and month.
So it is bug or I'm doing something wrong with filters ?
One problem is that you have an extra "?" in your query. You only need the first one, and then you can use "&" to delimit individual parameters:
https://api.cognitive.microsoft.com/bing/v5.0/news/search?freshness=month&category=business
You might also try adding a market to the query string, like so:
https://api.cognitive.microsoft.com/bing/v5.0/news/search?freshness=month&category=business&mkt=en-us
I'm using 7.0 and don't know what headers you're passing, so I can't test this directly, but it's possible a default market isn't being set. Since categories are market specific, then depending on how Bing handles this, it could plausibly prevent your category from being used.
I have found a similar question earlier here:
Google Analytics Visitors Flow: grouping URLs?
However I'm confused because people suggest different way to write the Replace String, and either way I try it am not able to make it work.
So I have a ecommerce site with hundreds of different pages. The different parts of the website is:
http://example.com/sv/ (Root)
http://example.com/sv/category/1-name/
http://example.com/sv/product/1-name/
http://example.com/sv/designer-tool/1-name/
http://example.com/sv/checkout/
When I go to the visitors flow. I want to see the amount of people that go from example Root to Category, and from Category to Product, and from Product to Designer Tool, and from Designer Tool to Checkout. However now when I have so many different pages it becomes very difficult to follow the visitors flow, because the product pages are for example not grouped together.
So instead of above. I would like to remove the 1-name/ part in the end. And only see /sv/category/, /sv/product/, /sv/designer-tool/.
In the earlier post I understand you can use an advanced filter to do this. I have set the following settings:
Type: Search & Replace
Field: Request URI
Search String: ^/(category|product|designer-tool)(/\d*)(.*)
Replace String: /$A1$A3
I guess that my search string and my replace string is wrong. Any ideas?
EDIT: I updated my filter to the following:
Search String: ^/sv/(category|product|designer-tool)(/\d*)(.*)$
Replace String: /sv/\1/
Still testing and unsure if it's the correct way to set it up.
I was able to solve this by the Search String and the Replace String in my edit above.
So basically what I did was:
Create a secondary view/profile for your site. If you apply your filter to your one and only view/profile that means that you won't be able to see any detailed data about specific pages, because the filter removes/filter that.
Add an Advanced Filter with the following settings:
Type: Search & Replace
Field: Request URI
Search String: ^/sv/(category|product|designer-tool)(/\d*)(.*)$
Replace String: /sv/\1/
You need to wait 24h after creating your new profile/view before you can see any data in it.
So my confusion was regarding the Search and Replace String. The Search String is an regular expression for matching everything after your .tld. So for example http://www.example.com/sv/mypage/1-post/, the Search String will only search within /sv/mypage/1-post/.
The Replace String is what it should replace the whole Search String with. So in my case, I matched all URL's that had /sv/category/1-string/. I wanted only to keep the "category" part, so I replaced the whole string with /sv/category/ by inputting Replace String /sv/\1/
/sv/ means just what it says. \1 means that it should take the value of the first () of my Search String (In this case "category"). The ending / is just an ending slash.
All in all, it means that any URLs that looked like http://example.com/sv/category/1-string/ was changed to http://example.com/sv/category/. Meaning that I can now see data for all my categories as a group, instead of individual pages.
Is there a way to make an exposed filter and contextual filter play nice with each other? I have the title field set as my exposed filter and then I also have a contextual filter in glossary mode. When I do a search with my exposed filter it works normally until I click on one of the letters for my contextual glossary.. then I get no results.
For example when I first come to my page it shows me that there are 35 records for the letter P. if I do a search for the word Christmas I get some results on the page but the number of records for the letter P still says 35. When I click on the letter P I get 0 results because the view is still being filtered by the word Christmas.
Is there anyway to make these two things play nicely with each other to get some results that make a little more sense? It would be nice if I clicked on a glossary letter than the exposed title filter would be reset.
Enable the filter_harmonizer module (Actually this module was publish after the question date)
(optionally) Disable AJAX for the views and set the contextual filter:
"WHEN THE FILTER VALUE IS NOT IN THE URL -> Display all results for the specified field" because by default it shows titles beginning with letter "a" in the first load.
You should try with changing the 'AND' for your filters to 'OR'
By default, if you check the added filters, they are added with 'AND' condition. So, each time you filter the result, its 'AND'ed with previous query.
Regards.