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
1 answer
830 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 ...
Gediminas's user avatar
0 votes
1 answer
5k 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": "[email protected]", "password": "...
Danilo P. da Silva's user avatar
0 votes
1 answer
2k views

Wordpress returns a wrong date

I am trying to get the todays date , day and time . Today is : 10th july 2018,tuesday and time is 3.23am For time the below code works fine: $wpplcurrenttime = current_time( 'g:i a', $gmt = 0 ); ...
user avatar
0 votes
0 answers
40 views

PHP calling AJAX function that relies on passed PHP function values not working

In reading I am not sure if the issue below could have something to do with needing a custom wordpress ajax handler? All of these functions are inside my functions.php file. I have a couple of PHP ...
Manny's user avatar
  • 3
0 votes
0 answers
442 views

how to display active, upcoming and past event with featured listing with pagination

I have a code that work fine for Active Events Page, Upcoming Event Page & Past Event Page with a event_start_date later than today. What I want is? A : To show Active, Upcoming, Past event post ...
gul rathod's user avatar
0 votes
3 answers
985 views

How to display only first value of database column in WordPress

I have following foreach loop code... <?php $usernames = $wpdb->get_results( "SELECT user_name FROM wpxa_project_members WHERE project_id = 698" ); foreach ( $usernames as $username ) { ...
Minesh's user avatar
  • 317
0 votes
2 answers
4k views

I want to remove the links from the term list returned by get_the_term_list

I want to keep this category title on my pages, but I don't want it to be a link. <?php echo get_the_term_list( get_the_ID(), 'portfolio_cats', ' ', ' , ', ' '); ?> Can anyone help? Thanks
Toronto's user avatar
0 votes
1 answer
2k views

How to use wp-ajax in wp-cron

I have create a custom wordpress plugin where i am using wp ajax. In class's __construct i have an action (admin_footer) in order to use wp_enqueue_script and wp_localize_script following wp ...
John478's user avatar
0 votes
1 answer
2k views

How to check for WordPress timezone type?

If you choose a city as a timezone it will save to the "timezone_string" option but if you choose a Manual Offset (UTC+1 for instance) it is saved to the "gmt_offset" option if you need the ...
user avatar
0 votes
2 answers
7k views

How to remove html comment from source?

Is any easy method to remove all html comment like <!-- wp_head()--> from source from every pages and posts? Maybe using functions.php? Is any easy method without plugin?
ნიკა ხაჩიძე's user avatar
0 votes
1 answer
274 views

the_title() & the_content() are retrieving Post details inside a Page, after calling a shortcode

I'm trying to create a custom theme, since I need to convert html pages to be used at WordPress. In about.php page, I have this shortcode to retrieve posts of a category: <?php echo do_shortcode('[...
compliance's user avatar
0 votes
1 answer
68 views

How to save the checked boxes?

What i am trying to achieve is this I have created a custom post(offer), i have another custom post created (listing). I want to add a metabox in listing, which will recieve check list of all offers ...
Nimesh's user avatar
  • 441
0 votes
0 answers
13 views

Selected dropdown option is not getting saved in the DB [duplicate]

I am building a function within my plugin where I have the list of available pages being displayed. What I want is for whenever a user selects a page from the dropdown, it should save the slug of the ...
Rajin Sharwar's user avatar
0 votes
1 answer
73 views

How can I save the selected page in the dropdown after anyone clicks on Save Changes?

I am trying to build a function for my plugin. Now, I am displaying the dropdown of all available pages. What I want is for when anyone chooses a page from there and clicks on Save Changes, the page ...
Rajin Sharwar's user avatar
0 votes
2 answers
406 views

How to set post to draft and not publish if the_content contains certain words?

We need to set posts to draft or to not be created if the_content contains certain words. This is not something needed on current posts, it is needed on users who publish posts going forward. As an ...
Johan Barnard's user avatar
0 votes
1 answer
189 views

Create guest author page via php

I am building a website that has many guest authors, but there is only one admin account that publishes it all. Instead of creating multiple accounts, which would be impractical due to the high number ...
usina's user avatar
  • 13
0 votes
1 answer
157 views

How to dynamically register custom post type

I have this code in a custom plugin. public function create_new_cpt( WP_REST_Request $request ) { $args = $request->get_param('newCptDetails'); $cpt = register_post_type( ...
devdev's user avatar
  • 1
0 votes
3 answers
9k views

How to load WP functions?

I have a mymail.php script which sends a email (I managed to do it using require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/class-phpmailer.php' );.) and outputs a plain text string (Such as "...
porton's user avatar
  • 801
0 votes
1 answer
1k views

Why can't I enter the wordpress admin interface?

I accidentally changed the url of my wordpress page, which I finally managed to restore in phpmyadmin, the first page of my website works, but the second page doesn't, and I can't even log in to the ...
Svicc's user avatar
  • 1
0 votes
1 answer
501 views

How to override a non pluggable and non hookable function in a Wordpress parent theme?

My parent theme has some bugs in a function I then want to override in my child theme. The thing is it is neither pluggable and hookable. It is just defined like so : // no if(!function_exists()) ...
user2183282's user avatar
0 votes
2 answers
244 views

Seriously stuck with some custom meta box/plugin stuff

I’m working on a small plugin - part of it needs to add several meta boxes to all custom post types. I’ve tried looping through my array of custom port types in various ways but I keep getting errors ...
Dan's user avatar
  • 95
0 votes
1 answer
3k views

index.php changed on its own

I'm a newbie WP person. I have a WP site that quit working. I checked a bunch of stuff and it ended up being the index.php file has a bunch of "stuff" in it. I replaced the file with the ...
Shawn's user avatar
  • 105
0 votes
1 answer
33 views

Php string not working in Wordpress Functions.php [duplicate]

How to pass the following code. <div> <?php $category = get_the_category(); ?> <a href="<?php echo get_category_link($category[0]->cat_ID); ?> "> <?...
rt5277's user avatar
  • 1
0 votes
1 answer
2k views

How to get only one category of custom post type?

I get all post successfully of CPT which are Order by meta_key value Date. Code is below $today = date("Y/m/j"); query_posts(array( 'post_type' => 'event', 'posts_per_page' => 10, 'meta_key' =&...
FRQ6692's user avatar
  • 149
0 votes
2 answers
1k views

Listing all sub-pages?

I'm wondering how to write a list of sub-pages of actually visited page. So I have 2 pages and 3 sub-pages for each: Colors [page] - Red [child of Colors - subpage] - Blue [child of Colors - subpage]...
Wordpressor's user avatar
  • 5,041
0 votes
1 answer
151 views

Print html when custom field has value inside while loop

I want to print a block of HTML only when get_field('cennik_title') has value assigned to it inside the loop, when there is no value inserted inside the custom field, the block should be skipped, but ...
RRR's user avatar
  • 111
0 votes
1 answer
35 views

how to add display_name from the users table to this query

how to add display_name from wordpress users table to this query thanks for the help SELECT a.post_title, b.meta_key, b.meta_value as level, c.meta_value as intro FROM wp_posts a LEFT JOIN wp_postmeta ...
flexi2202's user avatar
0 votes
1 answer
405 views

Where exactly do I write define( 'WP_DEBUG', true ) in wp-config file

would anybody know where I would write WP_DEBUG in wp_config file. I don't see it there. I would like to check why my javascript is not working. I have enqueued everything with php in the functions....
Spencer Halstead's user avatar
0 votes
1 answer
79 views

Design view breaking on Pages

For my client site,when i try to create new page and publish the design view was breaking but the blog post view showing properly, the site uses custom WordPress theme developed by the previous ...
Tamil Beyond's user avatar
0 votes
2 answers
1k views

Allow a user or role to view drafts and previews, but not other admin privileges?

How do I allow a specific user or a specific role to view drafts and previews, but not allow them to edit posts or have any other admin capabilities? I can add a custom capability to a role, but don't ...
Michael's user avatar
  • 281
0 votes
2 answers
109 views

Prevent post from being published and show error

I'm trying to prevent a post from being published if it contains certain words using the folowing: function jhnppWord($content) { global $post; $content = $post->post_content; $...
Johan Barnard's user avatar
0 votes
1 answer
37 views

Add to previous posts under post

Goal: After each post (that contains under a certain amount of words), display the two posts that were published before it in that category/tab. I found this on stack, where they do something ...
MantaRay's user avatar
0 votes
2 answers
40 views

category not display in word press grammatically

I'm trying to create a new category in the taxonomy.php called 'USSERS'. I have followed few examples online and got till this part. function insert_term( $name,$tax,$parent='' ,$slug='') { $...
user166752's user avatar
0 votes
2 answers
7k views

Set Primary category using the Yoast SEO plugin

function set_primary_on_publish ($post_id) { global $post; $categories = get_the_terms( $post->ID, 'category' ); // wrapper to hide any errors from top level categories or products ...
Dylan Smit's user avatar
0 votes
1 answer
912 views

Calling function from within functions.php returns unwanted value

I am trying to customize the output of the [gallery] shortcode to include comment count by this plugin: Facebook Comments for WordPress plugin I found a function by Zack Austin (shown below) that ...
jwp's user avatar
  • 169
0 votes
1 answer
109 views

explanation for activate_plugin function in wordpress core

This function is in plugin.php file in wordpress core. I read the code and didn't get quietly what does it do. Can anyone give some explanation for this function?
Mahdi's user avatar
  • 29
0 votes
1 answer
65 views

How to show order data by multiple ID?

I use the code. <?php echo '<table> <thead> <tr style="font-weight: bold;"> <td style="width: 50%;">Название<br>Сумма взноса</td> <td style="text-align: ...
Василий Маркин's user avatar
0 votes
2 answers
548 views

If Statement Post Formats: No post format selected

I'm working with post formats, most of my code looks similar to this: if ( has_post_format( 'standard' )) { echo '<?php get_sidebar(); ?>'; } if ( has_post_format( 'aside' )) { echo 'this ...
Lucas's user avatar
  • 220
0 votes
1 answer
3k views

Ajax call to my Wordpress website from an external application [duplicate]

I have on website on wordpress and a external web app. I try to make an AJAX call from this external web app to get some info from my wordpress site/ database but i got an error message 400. Here is ...
Tayfun Akaltun's user avatar
0 votes
1 answer
1k views

Data fetch and delete by ajax request

I have created a crud reservation form using ajax. The purpose of this form is when the user submits this from the user data will be stored in the database without page refresh. The full functionality ...
Ataur Rahman's user avatar
0 votes
1 answer
266 views

Ajax call doesn't work in frontend but it's working in backend (when I'm logged in)

Here is is the call: make_ajax_call( '<?php echo wp_create_nonce( 'tidplus-ajax-nonce' ); ?>', MyAjax.ajaxurl, 'section-frontend', 'page-ticket' ); Here is the .js code: function ...
dragos.nicolae's user avatar
0 votes
1 answer
2k views

Use wc_enqueue_js only on specific pages - nested add_action

In my plugin, I'm trying to add inline script using wc_enqueue_js only on the cart page. The rest of the plugin is also executed only on the cart page. The code below works fine, but I don't like the ...
Ryszard Jędraszyk's user avatar
0 votes
1 answer
2k views

How to Remove a Filter from the Admin List Table?

I don't want the "Registered customer" filter option for the Admin Orders page. I have tried to search for how to remove it. I have been inside the WooCommerce codes to see how it's implemented. And ...
Peter Westerlund's user avatar
0 votes
2 answers
868 views

How to block specific keywords from searching on WordPress?

I'd like to block some specific banned keywords from searching on WordPress. Or I'd like to show a redirect when someone search specific keywords. How to do?
Ronomor's user avatar
0 votes
1 answer
1k views

Get custom post type REST API not working

I want to load the content of a modal using the REST API of wordpress. I've added the show_in_rest param to the custom post type I've registered in my function file, but I'm unable to load it, I will ...
sialfa's user avatar
  • 319
0 votes
0 answers
237 views

Insert post without actions/hooks

I am developing a custom importer for WordPress (because we have a very custom setup and the available tools don't seem to work for our scenario). During this import, I'd like to disable any hooks ...
FooBar's user avatar
  • 444
0 votes
2 answers
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 ...
jw60660's user avatar
  • 1,516
0 votes
1 answer
635 views

MySQL query performed 4 times inside loop

I have enabled custom php in my pages through the use of the exec-php plugin so I can run more complex pages than the standard WordPress page. I have had no problems with this plugin so far. I have ...
Joshua's user avatar
  • 698
0 votes
1 answer
67 views

How to add 2 posts under another post? Formatting should be intact

The goal is to print 2 articles under an article IF the article is 200 words or less. I've had some help over at WordPress, but the code a couple of helpful people provided I can't integrate into a ...
ordresser's user avatar
0 votes
1 answer
2k views

List events by month

I am working on a WordPress site consisting of a custom post type called "events". Each "event" consists of a custom field called "event date". I'd like to organize all the "events" by months based on ...
user2971921's user avatar