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
0
votes
3answers
3k views

Custom Widget outputs the input but doesn't save anything inside the textarea

I've been working on my first widget, Everything works perfectly except it doesn't save anything I add to the textarea box. It will output the input on the website however. From research I think its ...
0
votes
1answer
1k views

add_rewrite_rule with bottom priority doesn't handle the Wordpress pages

I have a php file named test.php that outputs the page querystring parameter. I want to use add_rewrite_rule to serve my php file, while the WordPress pages which exist already or will be created ...
0
votes
1answer
3k views

How to add active class to custom menu using while loop and wp_list_pages

I am running wp_list_pages through a while loop to create a custom menu. By running it through a loop I can target specific elements to show. I need to figure out how to either target the classes ...
0
votes
1answer
6k views

Jquery ajax to custom php file: returning blank data

I created a custom php file, put it in my folder. The files does insert some data to the database to a custom table i created. require wp_path() . "/wp-load.php"; global $wpdb; $favorite_table = $...
0
votes
1answer
577 views

Geocoding an Exploded Custom Field Array

So, I'm having a little problem with crossing signals in WordPress between Google Maps' API and an exploded custom field. I want to be able to geocode an address that's been exploded from a custom ...
0
votes
4answers
69 views

POSTS list in WordPress by views

I need a code that causes: <?php while ( have_posts() ) : the_post(); ?> List according to the amount of VIEW, is like to list popular posts only that it will enter the table mh_postmeta, and ...
0
votes
1answer
413 views

Wordpress widget in custom theme

I created a custom theme and writing a basic widget for my wordpress based website. If I paste the code in functions.php the code works fine, however if I paste the code in a separate file and keep it ...
0
votes
1answer
91 views

Dynamically Override Fancy Title - Part II

I followed instruction by @pat-j and @cjbj in this answer: Dynamically Override Fancy Title and I got the result of override title. Now I need to dynamically change this title. I have written this ...
0
votes
1answer
325 views

Prevent publish status/date saved on transition_post_status hook

I'm using the transition_post_status to prevent a custom post type from being published based on a post meta field. It doesn't seem to work entirely, and that's where I need some help. Here is a ...
0
votes
2answers
7k views

populate dropdown wordpress form from database custom table

Trying to populate a drop down element of a html form in a word press page with data from SQL query in a php file in a php directory: site/php/. Php code is working fine: <?php require_once "...
0
votes
1answer
4k views

Create a new user using WP REST API and declare meta object

I'm struggling here with a question. I'm sending a POST to http://localhost/wp-json/v2/wp/users/ with this JSON data: { "username" : "johndoe", "email": "jondoe@gmail.com", "password": "...
0
votes
1answer
395 views

Looking for a better way to handle an ajax script that pulls in post data on click

I've developed a template page that displays a grid of "employees" (a custom post type). That part works fine, but I also needed to set up a lightbox to display additional details on click. To avoid ...
0
votes
1answer
4k views

Loading wordpress stuff on laravel site

I not sure why i failed to load the wordpress site on the laravel site. the following code, i tested on plain php without any framework - it work! but if i call from the file within laravel framework -...
0
votes
0answers
39 views

How to check from which page the user is coming to the current page?

Is there a way of doing this with WordPress aside from using $_SERVER['HTTP_REFERER']? Maybe something like a blend of $_SERVER['HTTP_REFERER'] and is_category(). Something like, came_from_category( ...
0
votes
1answer
818 views

How to create different menu's for not logged in visitors and for logged in members?

I'm creating a website which will provide services to members and I want to make it so that when a not logged in person comes to the website the menu is specifically designed for sales pages to make ...
0
votes
2answers
2k views

How to allow PHP In WordPress text widget

I want to add a text widget to my new WordPress website, but in the text widget there are some PHP snippets and I am finding it difficult to do it. Please help me Guys.
0
votes
2answers
3k views

Conditional Statement - check if post has an attachment image

I'm working on a conditional statement (in a loop) that looks for a featured image then grabs a default image if there is none, which I have figured out. But, I also wanted a way to pull the first ...
0
votes
3answers
384 views

Can we have a php “page” without a WordPress “page”?

Somewhere off of the homepage we need to show a container page which does some stuff with custom post types. Actually it doesn't matter what it does, my point is it needs to exist and be reachable ...
-1
votes
1answer
3k views

WooCommerce - Customer Order History Pagination

I'm trying to implement pagination into WC's customer order history that can be seen on the "My Account" page using woo_pagination(). https://docs.woothemes.com/document/woo_pagination/ The template ...
-2
votes
1answer
201 views

probleme adding Txt and Links in preg_match()

I'm newbie in PHP, i use this PHP code who work as a charm (@Brian Fegter) : add_action('template_redirect', 'foobar_explode_if_no_citation'); function foobar_explode_if_no_citation(){ #Get the ...
11
votes
1answer
11k views

What is This esc_html_e() i wordpress php?

why do developers use <?php esc_html_e() >? in 404 pages, what does it mean, how does it works?
5
votes
5answers
42k views

How do I use Shortcodes inside of HTML tags?

I tried to include shortcodes with a parameter in raw html output, like shown below: <a href="https://example.com/folder/edit.php?action=someaction&id=[foocode parameter='value']&edittoken=...
5
votes
3answers
3k views

Plugin update error message

I'm working on a client website where the framework requires a specific plugin version to work properly. With the follow lines of code in my functions.php file, it stops the plugin from updating ...
5
votes
1answer
6k views

How display widget by id

I fetched widget id this way: $the_sidebars = wp_get_sidebars_widgets(); print_r( $the_sidebars['sidebar-1'] ); It shows: Array ( [0] => recent-posts-2 [1] => recent-comments-2 [2] =&...
4
votes
2answers
4k views

why is translation not working on theme?

Background I am using the theme Rookie from Sportpress. I created a child theme. Translation files are existing, especially german in my case. Wordpress is set to german language. The Problem ...
4
votes
2answers
9k views

How can I call WordPress core functions in external scripts?

I'm trying to develop a code to call some Codex functions (https://codex.wordpress.org/Function_Reference) the problem is simple, I don't find any doc where read about how to start. I have a PHP ...
4
votes
1answer
2k views

Site Title and Tagline in Theme Options Page

I'm using the Options Framework Theme to put together an options page. The user(s) I'm building this for would like to be able to edit a few settings directly from this page, including of which - the ...
4
votes
2answers
1k views

Build a content and excerpt grid loop with paging and options for # of posts

What I'd like to do: on index.php, a loop that shows a selectable number of full posts using the_content and then below that shows a selectable number (the number of posts can be hardcoded in the ...
4
votes
2answers
548 views

load/require specific php files for specific pages/templates/post types

I have a plugin with multiple php files. I want to load some of them only when specific template files are loaded. I don't want to load everything. Currently, I'm doing it with add_action( 'wp', '...
4
votes
1answer
2k views

Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?

I have been follow a tutorial here: https://rudrastyh.com/gutenberg/remove-default-blocks.html Where it discusses how to remove default Gutenberg blocks like so: add_filter( 'allowed_block_types', '...
4
votes
2answers
587 views

Static Frontpage Pagination - Custom loop

I created a custom content template, assigned it to a page and coded the query. Everything appears to be working as they should. The only issue I have is with the pagination. So, when I go the second ...
3
votes
1answer
1k views

WordPress Shortcode and Dynamic CSS

I have a question I would like to ask to the WordPress developers, Usually when creating a shortcode that need to generate custom css how do you proceed? For example a simple button shortcode with ...
3
votes
1answer
4k views

urlencoding of the_title() doesn't work?

hey guys, <?php urlencode(the_title()); ?>doesn't take effect. this is my entrie line of code: <li><a href="mailto:?subject=<?php urlencode(the_title()); ?>&amp;body=<?...
3
votes
1answer
709 views

Can i check if user is doing any ajax request?

I make a custom user meta and its name is last_activity. I use this meta to get the date of user last activity and I updated the meta each time user open a page using WordPress wp_head action. My ...
3
votes
2answers
3k views

Date archives for custom post type

I have seen many questions/posts regarding this, but have yet to find a decent solution. Basically I am trying to do what wp_get_archives does, but for a custom post type (personally I am unsure why ...
3
votes
0answers
25k views

How to get Woocommerce Variation ID? [closed]

I am trying to create some additional functionality on my Woocommerce backend where I add a custom field to the variations section of backend of Woocommerce. However I cannot for the life of me ...
3
votes
3answers
12k views

How to disable wordpress confirmation email for new users

I need to disable Wordpress new user registration email confirmation link and auto generated password for new users. Users should be register with a password of their choice without email ...
3
votes
1answer
2k views

How to get author ID when an author page is being viewed?

I'm having problems getting the author ID in my plugin's init() method. I've hooked init() to wp: public function __construct() { add_action( 'wp', array( $this, 'init' ) ); } My init() method:...
3
votes
1answer
988 views

Custom Meta Field - Youtube embed

I created a custom meta field and I want to use it to embed a youtube video into the post. It works but when I post a code like this: <iframe width="640" height="360" src="//www.youtube.com/embed/...
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
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

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
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
2answers
5k views

Replacing a specific menu item

So, I understand how to target a specific menu using the following to add a custom code. <?php wp_nav_menu( array( 'menu' => 'Project Nav', // do not fall back to first non-empty menu '...
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

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
4k 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

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
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

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 ?

1
4 5
6
7 8
10