Categories
Mastering Development

WordPress Notice: Undefined variable

could someone help me with this. Seems like there are some php errors in my code where the index variable is not set. How could i fix it? About.php Code <?php // Template Name: About ?> <?php get_header();?> <?php if(have_posts()): ?> <?php while(have_posts()): the_post(); ?> <?php $args = array( ‘post_parent’ => $post->ID, ‘post_type’ => ‘page’, […]

Categories
Mastering Development

Woocomerce add products to categories and subcategories programatically

I need to add an inventory to a woocomerce website. I currently have an array that looks like this: [0] => Array ( [name] => Lenovo 0A36307 [product_id] => 0 [type] => simple [description] => Technical Specifications: Manufacturer: Lenovo Model: 0A36307 Model compatible Lenovo Thinkpad x220, x230 Excellent quality at better than new prices. [regular_price] […]

Categories
Mastering Development

Generate WC coupon programatically when order is processing – coupon code is wrong

Checked already dozens of articles and questions posted here – used tips from each of them already 🙂 My goal is to generate coupon with pre-defined details for specific product id, once payment is confirmed. And I want it to be generated manually. Here is my code: This is quite long but working function for […]

Categories
CMS Mastering Development Wordpress

How Display Posts on category

I had a problem, I converted an html template to wordpress, now I want a section Category Enable to display content using categories Does anyone know the solution and code? iam use a code and not work for category : <?php $a = array( ‘posts_per_page’ =>200, ‘offset’ => 0, ‘cat’ => ”, ‘category_name’ => ”, […]

Categories
CMS Mastering Development Wordpress

Adding author option to [products] woocommerce shortcode

I am trying to modify the shortcode usage: https://docs.woocommerce.com/document/woocommerce-shortcodes/#section-11 What I am looking was passing the author id from short code e.g to the query. With the reference of: https://wordpress.org/support/topic/adding-a-special-product-attribute-to-the-products-shortcode/ But the sample was a true/false parameter to trigger the $query_args change, seems it’s not exactly my goal. And the function below is the only […]

Categories
CMS Mastering Development Wordpress

Order is breaking wp_query

Have never encountered anything like this. Running a simple query of custom post types, show only those that the current user is the author, and sort them by a custom meta field. global $current_user; $user = wp_get_current_user(); $args = array( ‘post_type’ => ‘order’, ‘post_status’ => ‘publish’, ‘author’ => $current_user->ID, ‘posts_per_page’ => ‘-1’, ‘meta_query’ => array( […]

Categories
CMS Mastering Development Wordpress

Filter and order post by more custom fields

I have a problem with following code. I want to filter post by two input checkbox, for example a and b, and order the result by meta value (contained in relevant post as meta value num). The problem is when both input are selected, because in this case I’d like to combine all result and […]

Categories
CMS Mastering Development Wordpress

Async Loading of Custom Posts

I have a wordpress page template, where I’m loading custom posts. The code for fetching these custom posts looks as follows: template-parts/content-page.php <article id="songs"> <?php get_template_part( ‘partials/content/custom’, ‘songs’ ); ?> </article> partials/content/custom/songs.php $args = array( ‘posts_per_page’ => 0, ‘offset’ => 0, ‘category’ => ”, ‘category_name’ => ”, ‘orderby’ => $orderBy, ‘order’ => $order, ‘include’ => […]

Categories
Mastering Development

How to create posts with image custom fields, from front-end form?

I have a custom post type called companies in my WordPress website. It stores information of companies. People should be able to send a new post using a front-end form. The companies post has a few custom fields like Address, Phone, etc. I was able to create the text-typed custom fields using Contact Form 7 […]

Categories
CMS Mastering Development Wordpress

WordPress subcategory archive pagination in custom layout

I have blog with categories and sub-categories and use category.php for archive of main category posts, and added a custom layout for subcategory archive layout as subcategory.php (with a function). In this subcategory archive page, I need a numbered pagination but all I did it returns to 404 Not Found, here my code : function […]