Questions tagged [php]

For questions about the server-side programming language that the WordPress core, plugins and themes are written in. Questions about using PHP outside a WordPress context are off-topic but might be asked on Stack Overflow.

Filter by
Sorted by
Tagged with
2
votes
2answers
2k views

Correct use of curly braces vs alternative synax

In most themes I've looked at and WordPress core, I'm seeing the use of endwhile and endif. Is there a good reason why WordPress uses these instead of curly braces for block statements?
2
votes
2answers
2k views

if has theme mod

Does someone know how to write the next line in wordpress PHP, because i'm not that great with PHP. If_theme_mode has content echo { my content } else { other content }; thnx
2
votes
1answer
2k views

How to Remove Parents Category Permalink from Posts

Simply speaking i want to do something like this. http://example.com/parent-category/child-category/post-name change into http://example.com/child-category/post-name I found some solutions, but ...
2
votes
1answer
2k views

Multi step form, custom plugin

I have built a working multi-page contact form that has Zoho CRM & Slack integration. What I want to do is when a user goes to our contact page, they will see the first half of the form (step1....
2
votes
1answer
126 views

PHP Script within wordpress theme

I have a php script that I'd like to utilize within my wordpress theme. I'd like to restrict access to the page based on users belonging to particular groups so it's important to keep it within ...
2
votes
2answers
1k views

Get list of shortcodes from content

I need a list of every shortcode inside the content. Is there any way to list them? This is what I need: $str = '[term value="Value" id="600"][term value="Term" id="609"]'; So every shortcode ...
2
votes
2answers
8k views

How to turn off redirection from 'domain.com/login' to 'domain.com/wp-login.php'

I want to install something different than wordpress under 'mydomain.com/login', but WordPress automatically redirecting this link '/login' to '/wp-login.php'. Where can I turn off this redirection?
2
votes
1answer
2k views

How can I run a .php file located in my site's root folder?

I am trying to convert some data from custom post types into custom tables in my Wordpress database. I have written a PHP program to do this. It requires that Wordpress be loaded so I can use some of ...
2
votes
3answers
5k views

Passing JSON data from WP Query into AJAX causing NULL errors

I am currently using a WP_Query that'll trigger from an AJAX call when a button is pressed. The post meta fields lat lng will be used as location data for a google map. The query outputs fine without ...
2
votes
1answer
2k views

Bulk Image upload and one image for each post?

I have around 3000 photos, want to upload on WordPress. Is there any way to bulk upload all the photos as one image for each post ?
2
votes
1answer
831 views

WordPress Customizer: How can you have multiple active callbacks on one control?

I have the following two Customizer controls that displays a checkbox for showing/hiding content. Each checkbox is followed by an active_callback that shows/hides the corresponding controls when the ...
2
votes
3answers
971 views

“wp_enqueue_style();” don't load new edited style

First, sorry my english. I am using Local by flywheel to manager my site files and my wordpress version is 4.9.4. Here is the problem, When I use wp_enqueue_style('wharever', get_stylesheet_uri()); ...
2
votes
2answers
2k views

How can I access the “description” of a menu item?

Where you can add your menu in under appearance > menus, I have descriptions in. In my page, I want to be able to echo out that description. Not in the menu, but in my page. How can I access this ...
2
votes
1answer
4k views

How can update custom meta for all posts

How can update custom meta (likes) for all posts that have this meta? If i used something like this: update_post_meta( $post_id, "likes", 1 ); it's required to add the post id that I need to update ...
2
votes
3answers
6k views

How to Create a Directory in a Plugin Folder?

I am creating a plugin in WordPress Version 3.4.2. When the administrator submits a form, a new folder is created inside my plugin directory and a file saved in this new folder. But it gives me the ...
2
votes
1answer
10k views

Insert plugin content before body end

How do I make plugin's content appear in a place I want? For example let's say I have a plugin that output's a paragraph: echo "<p>foo<p>" If I do this it will appear on a page outside ...
2
votes
3answers
9k views

Plugin.php: PHP Notice: Undefined offset: 0 in

I moved a WordPress site from one domain to another and there were a lot of white spaces that needed to be removed. The only problem that is left are the following errors: PHP Notice: Undefined ...
2
votes
2answers
1k views

Activate different theme for temporary preview

I wanted that when i access my site with specific parameter, my site used a different theme at that moment (only temporarily, to show only to me as a preview). I want it for test purposes. Is there ...
2
votes
3answers
7k views

Run shortcode at certain resolution

I've gone a roundabout way of trying to ask a question about this here: Loading shortcode with ajax but figured it might be worth asking the fundamental question of what I am trying to do without ...
2
votes
1answer
57 views

Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?

So this may be a very noob question, but I believe if I can get the answer to this I can clean up code and speed things up significantly. I build projects using Woocommerce quite a lot, and in doing ...
2
votes
2answers
7k views

How do I make wordpress comment fields required?

Here is my form: <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" class="validate"> <?php if($user_ID) : ?> <?php ...
2
votes
2answers
358 views

Change dns-prefetch to preconnect with correct protocol

I have this function in my functions.php file: function dns_prefetch_to_preconnect( $urls, $relation_type ) { if ( 'dns-prefetch' === $relation_type ) { $urls = []; } if ( '...
2
votes
1answer
3k views

Specified file failed upload test. wp_upload_handle

So I managed to write a peice of code that allows me to upload a zip file, im not even sure where it gets uploaded too, and I am doing it on my localhost with apache in control (www-data). the code is ...
2
votes
2answers
2k views

Saving metabox repeatable fields

This is a code that I'm adapting from https://gist.github.com/2057532. The problem is that I'm not being able to save the content from the new fields that I created. I had checked the other questions ...
2
votes
2answers
3k views

If in parent category

I have this structure Category > Subcategory > Post I´m trying to display some content if the user it´s on a specific category, or in it´s subcategory or post. I´m using this code but it only works ...
1
vote
1answer
1k views

Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied

When I load the content using ajax it doesn't apply MediaElements.js to my audio player, so the audio isn't display. I think this is because the MediaElement.js is loaded with wp-footer(), and this ...
1
vote
1answer
1k views

Correct way to make static pages editable in wordpress

I am in the process of converting a small static website with 5 pages into a WordPress site. I have created a custom theme and created the pages (Home, About Us etc) from the Wp backend. I have ...
1
vote
1answer
561 views

Retrieving all data from repeater fields

I have a custom field in WP called what_we_do_textarea_two. what_we_do_textarea_two is a simple repeater field which allows you to add another item to a list. what_we_do_textarea_two has a subfield ...
1
vote
0answers
1k views

How do I hide specific user profile fields?

I am using a membership plugin which pulls default WordPress user profiles to a directory. I want to hide these fields from my registered site users. I have searched for plugins and found nothing that ...
1
vote
0answers
25 views

Limit Authors to their Own Posts on front-end excluding admins

I'm trying to limit custom post type "Projects" only to post authors excluding the admins. I'm trying the following code: function project_view_for_only_author($query) { global $current_user; ...
1
vote
1answer
39 views

Targeting single page with JS

I created a JS and PHP code to query a database and display matching rows on a page. It was messing up other pages on WP, so I wanted to know how to target a single page so the JS doesn't run on ...
1
vote
1answer
85 views

How to save Clicks of a download link button while it doesn't matter if we refresh the page or again login/logout

I am working on a wordpress site and i am little stuck into one situation , what i want is that:_ I have one resume page, which shows resume posts from wp_postmeta table and each post have a downlaod ...
1
vote
1answer
769 views

Wordpress shop: enable custormers to select product color using image thumbnails on Custom Fields

I use Wordpress Custom Fields to provide customers with various product color codes in a drop-down list, but now I would like to add the various color thumbnails for ease of selection...similar to how ...
1
vote
2answers
3k views

How to change / delete product short description in Woocommerce

How to change / delete product short description in Woocommerce I use $short_desc = $post->post_excerpt; to read the property but I cant change it with wp_set_object_terms($post->ID, $post-&...
1
vote
3answers
1k views

get_the_content if it contains multiple lines it results in SyntaxError

I use get_the_content to pass to a javascript variable, and then back to another PHP function. This works great, but there is an issue when using get_the_content. If the post contains only one line (...
1
vote
1answer
713 views

Fix 403 error on WordPress multisite network using subdomains

I've a WordPress installation that I've transformed into a multisite network. I'm using cPanel and I've followed all the instructions to configure the WordPress installation. I've set up the ...
1
vote
1answer
1k views

Accessing a random image via ajax

The goal with this is to create a random banner, managed in the wp admin. I can create a banner solution in the wp admin without an issue but need a little help on the ajax side. I have an image ...
1
vote
0answers
38 views

Dynamically loaded Theme components based on Customizer Settings values : changes not appearing in Customizer preview - (Workaround found)

I'm trying to create a WP theme (for personal learning purposes, still pretty new to wp) where Header/Container/Footer are each chosen based on a dedicated customizer setting (still plain text, ...
1
vote
2answers
166 views

OOP Plugin Development. Including external object

I am developing a plugin by using classes and object oriented programming. Within my plugin I have included another object as I need to use the functionality of this other object. I am instantiating ...
1
vote
1answer
1k views

How to use copy() function and paste file in /wp-content/themes directory

copy("http://localhost/medium/theme.zip","themenew.zip"); currently it is pasting file in wp-admin folder, Is there any way I can copy .zip file to /wp-content/themes directory. Thank You :)
1
vote
1answer
400 views

file_exists() acting weird

I'm trying to pull some data out of a csv file but I'm stuck because file_exists() says the file doesn't exist when used with get_template_directory_uri(). This is the short code: function ...
1
vote
3answers
303 views

Wordpress Customizer not setting default value upon initial install?

I'm having some issues getting the default values set in the WordPress Customizer to save to the database upon initial install without first having the user save the Customizer to set them. I've tried ...
1
vote
2answers
3k views

Using Echo in ShortCode - Stuck

After about 3 days of searching and tinkering, I'm stuck. I'm not a coder, but I like to try. I have a short code that gets a horoscope from a table in my WordPress database (I created the table). ...
1
vote
2answers
128 views

Want to separate sections of posts. Can you restart loop?

I want to break the loop into sections of posts so I can put content in between that doesn't repeat. Is it possible to end the loop and restart? My code works for my layout works if there are 10 ...
1
vote
0answers
573 views

Trying to disable plugins doens't work

I've developed a small plugin which empties the $plugin variable. And put it into the /mu-plugins folder. But it doesn't work. What am I missing? The plugin is executed. If I do a print_r on $plugin ...
1
vote
1answer
208 views

Prevent WordPress from loading comments

I'm displaying the comments for a post my way, using $comm = get_comments() and then passing $comm to wp_list_comments() (this is the reason why). How to disable WordPress from loading comments from ...
1
vote
1answer
601 views

Thumb rating for wordpress - top user

I am currently using gd star rating (thumb rating) to rate posts (articles - no rating on comments). What I really want to do is show a table of the top 5 users and their number of votes based on the ...
1
vote
2answers
8k views

Notice: Constant already defined in wp-config.php on (non-existent) line?

I've been tasked to move a website into a new domain, and I've encontered this weird issue. On the homepage, I always see these: Notice: Constant AUTOSAVE_INTERVAL already defined in /home/gturnat/...
1
vote
1answer
3k views

How can I call a row of user specific data from a custom table added to the WP Database

I have setup my WordPress site, customized the Theme as well as a couple plugins, I have also added a custom Table to the WordPress database that will contain user specific information. I am wanting ...
1
vote
2answers
5k views

how to create and show sessions in word press?

I am new to word press but know all the required PHP skills. I am using a form to create session in one page and then accessing those sessions in another page. I have done this already without word ...

1
5 6
7
8 9
11