Questions tagged [wordpress]

WordPress is a free and open source blogging tool and a content-management system (CMS) based on PHP and MySQL.

Filter by
Sorted by
Tagged with
0 votes
1 answer
44 views

Default to array when value is null or false

I'm working with ACF in WP which provides a get_field() function. The function can return an array of values, null or false. ...
  • 158
0 votes
0 answers
50 views

How to optimize a search between dates in a WP Query?

In the posts I have a date field and a start and end date range. I need to query if it matches date or if it matches between the dates in the range. This Query works, but how can I optimize? ...
3 votes
2 answers
160 views

Modify a WordPress loop to show posts of certain categories, based on user roles

I've got some code that works as intended, but I have a feeling that it's messy. This code is modifying a wordpress loop and the goal is to check the roles of the current user and show posts of ...
  • 33
2 votes
2 answers
110 views

Optimize PHP code for Wordpress shortcode (Star-Rating)

I am using WP with the Avada theme and the built in Star Rating element as well as ACF Pro. Unfortunately I found out that the Star-Rating element adds a rating scheme to the footer of the website ...
  • 21
0 votes
0 answers
29 views

Wordpress Custom Block that sources files from the theme images directory

The Goal Current PHP version 7.3.5 The block will have a function that sources a defined set of illustrations that are stored in {themeName}/images/illustrations. ...
  • 401
0 votes
0 answers
43 views

Recreating WP Columns Block - Columns Container Only

I have been working on recreating the WP columns block using server-side rendered blocks. For the base creation of the block structure, I have used ...
  • 401
3 votes
2 answers
57 views

Custom Block with ACF in WordPress

I'm learning and want to improve as much as possible. In doing so I have written this custom block that has an image on one side and an inner block on the other. It's using ACF to get the variables ...
1 vote
1 answer
43 views

Instantiating classes in WordPress plugin

the last couple of weeks i have been working on my own WordPress plugin. I am trying to do a class based codebase. My plugin works correctly, but i don't really know if this is the correct way to ...
2 votes
0 answers
29 views

Added custom woocommerce product page hook

I inserted this code snippet in the functions.php of my child theme, to create the woocommerce single product page in the hook woocommerce_after_single_variation of the custom icons in line centered ...
  • 21
1 vote
1 answer
58 views

Building a pre-loader for performance gains in Wordpress

As the title states, I am building a pre-loader for Wordpress running on PHP 7.3.5+ that will deliver performance boosts in loading, as well as metrics such as Google Page Speed. This is something ...
  • 401
3 votes
4 answers
100 views

Order a table by column and get row number

In my database, I have table wp_postmeta, example: ...
-1 votes
2 answers
100 views

Woocommerce order change status

This code can woocommerce order change status. But as you can see, this code is hard to read. How can I make it cleaner? ...
0 votes
2 answers
71 views

Optimizing large WP Query [closed]

I have WP Query like this: ...
  • 3
2 votes
0 answers
39 views

Copy the reply button to each comment thread in WordPress. Converted from jQuery to JavaScript

I converted an old Wordpress Plugin of mine from jQuery to plain JavaScript using a cheat sheet. I was very surprised that it seems to work right out of the box on my first try. ...
  • 121
3 votes
1 answer
50 views

Query WordPress database, returning an array of rows

This is one of my first attempts at querying the WordPress database for data, and some my first PHP code ever, so please bear that in mind when commenting. It is supposed find data between two dates, ...
  • 31
3 votes
1 answer
69 views

I need a better way to add css per each page on wordpress

I just started to use WordPress to start building a website, but as I need to use the get_header() function to retrieve the ...
2 votes
0 answers
24 views

wordpress slow query shown in query monitor

I have a slow query on a wordpress site. How can I rewrite this to make it faster? I'm not having much luck. The query takes about 0.900 seconds I have both the query and the explain below, my goal is ...
  • 21
3 votes
2 answers
122 views

Wordpress Ajax Custom Query - High CPU LOAD

I'm developing a fully AJAX community WP theme that comes with a lot of custom queries. Everything is fine, there is no bug but recently but I had a few clients that have a huge database and my theme ...
1 vote
2 answers
271 views

Dynamic Accordion in WordPress

I used the Bootstrap v4.0.0 accordion to display my business services. Further, I created a custom post type "service" for my services (Each service is a post). To display my services ...
  • 41
2 votes
1 answer
81 views

Efficiently use array values and variables in a WordPress template

Is it better to validate and put an array value into a variable at the top of a file or to check the array value directly right before output in the file? I work at a WordPress shop and we have a ...
5 votes
1 answer
112 views

Wordpress single post content class customization with if-else function

I have the following code, which displays the content for my custom page template "landingpage.php" and for single posts. The site uses Bootstrap 4. ...
1 vote
2 answers
109 views

Shorten and optimize php custom code for wordpress page template and use shortcodes

I'm pretty new to php coding, but i know wordpress for a long time. Also experimenting with bootstrap. I created a new Page Template and modified it a bit. What I'm looking for is to optimize this php ...
2 votes
2 answers
62 views

Function for iterating out an unordered list of custom taxonomy terms

I've created a function that generates an <ul> of my wordpress custom taxonomy terms, displaying ...
  • 195
2 votes
1 answer
57 views

Display content if form field is filled - Do not display if field is empty

I am using the following code within the footer of my test site. I am using WordPress and Advanced Custom Fields The intention is: To display the HTML container ...
  • 401
3 votes
1 answer
48 views

Performance of WordPress Plugin is currently very bad and needs to be improved

I have written the following Plugin, which adds fields to the Media/Attachment Entries and returns all information in one Shortcode. This solution works, however, is pretty slow the more entries ...
4 votes
1 answer
29 views

Simple Bespoke WordPress Integration Plugin

I am in the process of setting up WordPress with WooCommerce, one of the requirements is a bit of integration that takes a person from another website directly to a specific product. I have set the ...
2 votes
1 answer
197 views

Replace anchor tags and force create new tag with custom attributes

I'm just use the add_filter('the_content', function($content){}); for filtering anchor tags in a post. Basically, I want filter anchor tags to appropriate format. ...
1 vote
1 answer
44 views

Improved the output of the related posts in WordPress

I made a simple code to improve the results for WordPress related posts area and it works fine , but because my experience in coding is low , my code is very long and i believe that there is a way to ...
  • 43
3 votes
1 answer
58 views

WP/PHP getting API data and using hook

Below are the two things I'm trying to solve, logically. This is just a proof of concept; and I'm not implementing this on real data nor via full plugin at this time. Just looking at logic and syntax ...
3 votes
0 answers
446 views

Product Filters wordpress plugin: implement single responsibility principle for elements classes

Plugin is a small editor that allows to create a filter such as a price slider, checkboxes of "brands", a drop-down of "seasons". An example of how plugin work can be seen on page: http://demo-...
1 vote
0 answers
41 views

WordPress plugin to reveal coupons after several visits to a page

My file tree is here. It does not look good. I would appreciate any tips you have on improving code organization. My React mindset of breaking folders by component didn't carry over well into php/...
  • 111
2 votes
1 answer
574 views

Prefixing prices of certain product categories with text in Woocommerce

I had the need to prefix the price for certain product categories on only the shop page (because the price can be higher depending on extras that the customer might want). These were my requirements ...
  • 153
3 votes
1 answer
54 views

Filtering wordpress comments by votes

I have a website that, based on a user's comments, filters comments by "most liked first, most disliked first" etc... I have a custom table for comments scoring system and system working with +1 and -...
0 votes
0 answers
39 views

WordPress hook to add URL-rewriting rules for articles with language variants

Please look at this working WordPress code: ...
1 vote
0 answers
31 views

Custom WordPress SQL query to get posts and users using term_id

I have a WordPress site with multiple custom post types, that all share a common custom taxonomy. Users can also be tagged with terms from this taxonomy. After giving up on ...
1 vote
0 answers
68 views

Proper image sizes in WordPress

I wanted to create a set of functions that would allow me to easily implement images for multiple screen resolutions in my custom page templates. WordPress offers some functionality for implementing ...
  • 158
1 vote
0 answers
30 views

Simple cart update WordPress plugin

I created a plugin to update cart automatically on quantity change with some additional options. I want to focus only on the main plugin file, skipping uninstall.php and .js file which are entirely ...
2 votes
0 answers
124 views

WordPress rest api basic auth with IP check

I'd like to use basic auth with the WordPress API, but restrict the capability to a single IP address. I've updated the existing code from here: https://github.com/WP-API/Basic-Auth accordingly. It ...
  • 121
1 vote
2 answers
497 views

PHP subscription workflow

I've creating a working subscription workflow for my webpage, which heavily utilizes a set of functions I've created for this purpose. However, after doing some testing (functionality works fine), I'...
  • 11
1 vote
1 answer
72 views

Feeding PHP variables to a number of HTML elements

The following code works fine, however, I'm trying to simplify it. I wrote it but I'm a beginner PHP coder. I can see that most probably the use of a function or class would be better... or anything ...
  • 537
1 vote
0 answers
581 views

Load more and filtering - WordPress AJAX

In my WordPress theme I have built a function that uses Isotope Layout by Metafizzy to accomplish filtering and sorting. I have used a mix of AJAX and JQuery to accomplish this, however I feel the ...
2 votes
0 answers
244 views

Generating two Woocommerce Order CSV files based off url query

I wrote this code about one year ago. I'm looking to refactor it to be solid SOLID and secure, as this is being generated off a custom endpoint. The script is to read parameters from a query and ...
  • 183
2 votes
1 answer
107 views

Checking if a shipping method exists

I am trying to create a custom WordPress/WooCommerce function in PHP. I am a newbie and would really appreciate some feedback on my code and how to improve the code! Right now it feels like there is a ...
  • 123
2 votes
0 answers
29 views

Create a new WordPress admin page, and add an admin table to it

I completed this WordPress coding task as part of an interview. I'm hoping someone can review my work and comment on everything, especially my general approach to the task, and the sanitization of ...
  • 121
3 votes
3 answers
232 views

Check if a postcode is in a list

I'm looking for improvement / advice / reviews on how I can improve this code. I feel like there is a better way or more efficient way of doing this and I am over looking it. The Plugin I made is ...
2 votes
0 answers
34 views

WordPress plugin for shipping calculation

I am writing a WordPress plugin that allows shipping calculation on the product page. Originally, shipping calculation is only available in the cart. To calculate shipping costs on product page, ...
1 vote
0 answers
33 views

WordPress plugin development - plugin-name.php file and plugin files/folders structure

I am creating my first WP/WooCommerce plugin. I was following instructions from WordPress Codex during development, but I wanted to review it here, to make sure I am on the right path. First things I ...
  • 111
1 vote
0 answers
47 views

WordPress plugin for listing users

I was given an opportunity to join a WordPress contractor/freelancer website and was asked to build a plugin that would list the wordpress users in the database, allow you to filter them based on ...
0 votes
1 answer
142 views

Formatting fractions found in a given string to html fraction

I'm working on a site running woocommerce and wp where the user will add/has added a dimension attribute. The dimension string will take the following format originally: Ht: 30 1⁄2" W: 22 1⁄2" D: ...
  • 158
5 votes
1 answer
588 views

JavaScript responsive menu (dropdown/dropup)

I have the following front-end code for a responsive navigation menu which I thought using in my WordPress website. Clicking the .burger element should cause ...
user avatar