Fetch results based on parameter WordPress - php

I'm attempting to customize a wordpress theme. I've added custom field cp_job with form submission. This indicates if the ad is either Buyer(Buying services) or Seller(selling services), which is now complete.
Now I want to fetch results based on buyer or seller. In this wordpress theme classipress they have "Ads" on the side:
I simply want to fetch ads which have the attribute buyer or seller, which I assume is under the MySQL column cp_job. These ads will return the ad with all columns. Doing this in native PHP and MySQL would be easy but working around this theme/wordpress is way more complicated as I don't understand WordPress syntax.

You can use wordpress custom query to fetch record from any table.Like
global $wpdb;
// return array of object
$dataArr = $wpdb->get_results(" SELECT col FROM table WHERE cond = data ");
Then you can do foreach on records like below:
foreach( $dataArr as $data ){
echo $data->col;
}
Hope this helps ;)
Cheers!!!

Related

display wp_postmeta meta_value in wordpress woocommerce

please help a new member
THE ISSUE:
I have a POS on my WC and it doesn't display sequential orders numbering, so I am using other plugin to achieve this. I need to display the value of a meta_value from my database in the order receipt (printable ticket) after the order is placed. So, the meta_value I need to display on the POS's tickets is the sequential ticket number created by the other plugin.
Gladly this other plugin creates the sequential number in the database from where I hope I can retrieve it somehow.
This meta_value for example "T00001...T00009" has the meta_key = "_order_number" and it's within wp5o_postmeta table of my sql database.
I believe it must be easy for you guys...
Thank you so much
Image of the data
use this filter and implement your post meta
wordpress/wp-content/plugins/woocommerce-openpos/includes/front/Front.php
line 4683
$result['data'] = apply_filters('op_get_next_order_number_info',$order_number_info);

Contentful: how to query entries that have one of either entries attached?

I'm trying to filter blog posts based on 2 or more categories.
The blog posts are a content type and the categories are as well. Each blog post can have only one category. The category is connected to the post via a reference field. I'd like the user to be able to filter the posts. The user can select multiple categories at once.
It seems I'm unable to fabricate the query. Here's what I have so far:
// PHP
$categories = ["79RwpuYXo4W9FiYMdpeShj", "4CAkZRYSa3EB23ipTwZ92R"];
$query = (new Query)
->setContentType('blogPosts')
->where('fields.postCategory.sys.id', $categories, 'in'); // using 'all' instead of 'in' also doesn't return any results
In my mind, this should get all blog posts that hold a reference to either category entry (id). However, no entries are returned using this query. I'm using contentful/laravel v4.0.
Okay, I figured it out. I'm using Contentful Core v2. The correct query structure for v2 is the following:
// PHP
$categories = ["79RwpuYXo4W9FiYMdpeShj", "4CAkZRYSa3EB23ipTwZ92R"];
$query = (new Query)
->setContentType('blogPosts')
->where('fields.postCategory.sys.id[in]', $categories);

How to fetch posts with pagination feature in WP on a custom table?

I have a custom table that I created named cars_plugin and it has columns id, name, color, model
Now, I can get list of cars using
$sql = "SELECT note FROM cars_plugin WHERE ID = '$id'";
$query = $wpdb->get_results($sql, ARRAY_A);
foreach($query as $car){
// list cars here
}
The above code works as planned, and I could create a pagination for that, although it will be difficult, now my question is, if I have a custom table like that how do I query the table so I can be able to use the built-in Wordpress pagination functions?
This can't be done I think
I found no way to use WordPress default pagination for custom table. Cause the default pagination is initiated in WP_Query class which is curated or built or written only for querying posts from {wp-table-prefix}_posts table and may be joining other table related to posts.
So what is the solution ???
May be you can create your own class which will return you the result with pagination and this could be by extending WP_Query class. But this method will need a lot of modifications to manipulate the base class default methods. So I would prefer writing a separate new class for this than extending the WP_Query.
Another way would be straight PHP method. You can chunk the queried result and show them page by page. And I think it would be the easiest and smart way to do pagination for custom table in WordPress. For finding more on this method you can check those below links-
https://wordpress.stackexchange.com/questions/53194/wordpress-paginate-wpdb-get-results
http://www.walkswithme.net/wordpress-pagination-for-custom-tables
Hope that helps.

Search Engine of Open Cart

Can anyone Please tell me how the search engine of the Open Cart works. I mean to say where is the code for the search in Open Cart. Which database tables are uses to search any query?
OpenCart Search Form submits to route=product/search i.e. catalog/controller/product/search.php. This file calculates results based on submitted keywords and then loads product/search.tpl template to display search results.
Search results are generated by the controller using catalog/product model's getProducts() function. The same function used for generating ordinary product lists.
OpenCart uses a basic search (just matches any keywords in your search), though there are other search methods available in the extension store. The tables it uses in the default are the product and the product_description tables
Open-cart search in the category levels according your filters join with category_description table and the products titles join the product_description Table all this according the current user Language
you Can find this code in Product Model
\catalog\model\catalog\product.php
public function getProducts($data = array()) {

Get multiple results from db

I'm working on a fairly large project in (object oriented) PHP which includes a webshop where users can buy products and additional licenses and services. Purchasing is a four step process:
Step 1: User chooses a product, and product_id is passed to step 2
Step 2: Fetching and outputting all license types based on product_id, passing product_id on to step 3
Step 3: Fetching and outputting all services based on product_id, in a form with checkboxes named services[$service_id]
So now, on the checkout on step 4, I fetch the correct products and licenses from the database, but I also have to get the correct services from the db based on the services array, and calculate the price to output. At last, I'll have to assign the services array to the Smarty template.
How would the most suitable way to do this be? I really hope that someone is kind enough to help me out here, as I'm having a very hard time trying to make this work.
Thank you so much in advance.
Try using
$resulter = array();
$i = 0;
foreach($product_id as $value) {
$query = "Select FROM products WHERE product_id = $value";
Your execution code
$resulter[$i] = $result; //$result could be a assoc array
$i++
}
And If I ware you I would i would use a multidimensional array like I shown above.
Sounds like you need a JOIN.
Something like a JOIN on the 'products' table and 'licences' table using the 'product_id' field to make the join.
An example query would be something like:
SELECT <required_fields_here>
FROM products
JOIN licences ON licences.product_id = products.product_id
WHERE product_id = <product_id_here>
Note that in the SELECT section you can select fields from both 'products' and 'licences' tables, you just need to prefix with the table and a dot e.g. 'product.product_id'
I think you will need to be more specific if you need further help. Hope it helps.

Categories