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

Filter the blog title displayed in the header

I wanted to filter the blog title displayed in the header to apply different CSS styles to different title parts/words, so I added the below function to my (WP 4.7) Twenty Seventeen child theme's ...
2
votes
1answer
14k views

exclude multiple terms using get_terms() function

I am using this function to filter category terms from a calendar: $terms = get_terms( TribeEvents::TAXONOMY, array( 'orderby' => 'name', 'order' => 'ASC','exclude' => array(77)) ); ...
2
votes
2answers
13k views

Wordpress redirect to landing page if not logged in

I'm using the following code in my functions.php file to redirect users who are not logged in to a particular landing page <?php if(!is_user_logged_in()) { wp_redirect( 'http://www.mysite....
2
votes
2answers
342 views

Comment filtering (search)

Basically I want to develop the ability to search comments on my site. A form with input field where the visitor can enter a search string, which tells WP to display only comments that contain that ...
2
votes
2answers
1k views

Rename existing old uploaded images containing accented French characters (not during upload)

Need to update 1,000+ images which have French characters in them. The following worked for a test post: Created a copy of the image without the FR characters Updated file name inside the ...
2
votes
3answers
6k views

Limit number of pages in pagination

I have more than 500 posts and I want to limit only 100 posts with pagination. So, 10 pages with 10 posts in each. Presenting you the code: $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' )...
1
vote
1answer
1k views

Limit the Excerpt field in WP-Admin in words

Is it possible to limit the Excerpt field on the post page in words? Note that I am aware that it's possible to echo the excerpt and limit it in words, but I want the field itself to limit the amount ...
1
vote
2answers
797 views

Utilize WP-CLI from inside WordPress, not SSH

I'm looking for a way to test out some WP-CLI commands but from the Debug Bar Console where I normally test PHP. For cases when I don't want to switch windows to SSH, this might be a way to reuse/...
1
vote
3answers
1k views

Delete post revisions on post publish

Is it possible to delete post/page revisions from the database when a post/page is published? 11/05/12 Answer: See the plugin below by bueltge I want to do this on a site with 5,000 posts and 125,...
1
vote
2answers
2k views

How to use WordPress (PHP) functions in AngularJS partials files?

I am using AngularJS to load a list of my WordPress posts, however I can not get any of my PHP functions to work with my partials file. I've tried using something such as search.php instead of ...
1
vote
1answer
5k views

Run W3 Total Cache Flush Function with Crontab [closed]

Ok. I'm really stumped on this one. Basically, I need to call a function for the Wordpress plugin W3 Total Cache as part of a cron job in crontab. I'd like to automatically clear the entire page ...
1
vote
2answers
828 views

count number of user comments with a specific comment meta value

I am using the code below to count the number of comments by a certain user: global $wpdb; $count = $wpdb->get_var( 'SELECT COUNT( comment_id ) FROM '. $wpdb->comments .' ...
1
vote
1answer
6k views

Copyright info change in Theme Child PHP

Below is the file where the information is pulled from. I have tried adding the /inc folder to the child theme and adding the template-tags.php with the changed but this does not make any affect. /...
1
vote
2answers
6k views

How to list the Hooks and order of execution in current loading page? [duplicate]

I need to know the list of hooks that are called in the current page . How to identify the priority assigned to the action and filters in the action . If i want to remove the default action on word-...
1
vote
3answers
662 views

Two-step login process - Is it possible?

Is it possible to do the following with Wordpress (without hacking too much code - I would like to make this a general plugin using simple hooks)? Log in with the username/password. If username/...
1
vote
1answer
6k views

How can i create a function to get youtube video time

Tom J Nowell posted this code to help me retrieve the YouTube video time. Functions // function to parse the code from the URL function parse_youtube_video_id_from_url( $video_url ) { $...
1
vote
1answer
484 views

Add custom image sizes to media uploader

I want to add custom image sizes to the media uploader: In order to do this, I use the following code (comments are there for convenience): // this function adds the custom image sizes to the media ...
0
votes
1answer
3k views

Export all post from database to JSON only when the database gets updated

I'm trying to export all the published post of my database to a JSON file, in order to use it in JS. Here is the code: <?php /* Plugin Name: Export to JSON Description: Creates the JSON file that ...
7
votes
4answers
2k views

Wordpress and event-driven programming - what is it about?

I want to state very clearly that this does not intend to revive the discussion about functional/procedural programming versus object-oriented programming. There is plenty said about that, on WPSE and ...
6
votes
1answer
5k views

Disable Attachment Pages Completely

I would like to disable all attachment pages completely. I Googled it, but there's just information on how to redirect to parent post or homepage. That's not what I would call an elegant solution. Why ...
6
votes
1answer
944 views

Inject post (from specific category) between posts in Loop

I would like to add a post (from specific category) between posts in the WordPress Loop (such as 'Sponsors'). Example: P P P S P P S P P S P P How can I achieve this? I am a beginner with coding, so ...
6
votes
1answer
5k views

Ajax Load More Posts in Category Page

I am developing a theme where I need to load more posts with ajax. Currently, when I click load more on the category pages, all the posts are loading. The category.php looks like this : ` ...
5
votes
1answer
1k views

Hide custom image sizes from media library

I want to hide a few custom image sizes from the media uploader: The following code (posted here) works only for the default image sizes: function remove_image_sizes($sizes) { unset($sizes['...
5
votes
1answer
29k views

Retrieve POST data from AJAX call

I have the following JS script : jQuery('#form-recherche').submit(ajaxSubmit); function ajaxSubmit(){ var newFormRecherche = jQuery(this).serialize(); jQuery.ajax({ ...
4
votes
2answers
890 views

Hide old attachments from wp media library

I am trying to limit the files that are shown in the wordpress media library popup (from wp_editor). Currently every single file that I have ever uploaded to my site is shown in the library but I ...
4
votes
2answers
1k views

Get php var inside javascript file (making plugin)

I was making a plugin and I have a javascript file where I want to take some options saved in the database to show well the function. So I have this: function wp_home(){ wp_enqueue_script( '...
4
votes
3answers
7k views

How to set custom cookies before output

What's a surefire way to check/set cookies before the php headers are sent? Is there an action or filter that would be the best place to hook a setcookie() function?
4
votes
2answers
4k views

Searching users with WP_List_Table plugin

I am trying to devlope a plugin that will search and return my users so I can edit some other metatdata that belongs to them. I have been using the plug-in listed on the Codex as my starting point. I ...
4
votes
4answers
6k views

PHP - redirect https to http and www to non-www

**EDIT: I finally figured this out. Scroll down for my self-answered self-accepted answer (green check mark) ** I'm currently using functions.php to redirect https urls to http for a site which ...
4
votes
4answers
4k views

Sorting list of sites from multisite network using wp_get_sites

I have a loop that pulls in all sites in my multisite site network and loops through them to get variables located in their ACF options. Here is an excerpt from the code I am using: $stageurl = ...
3
votes
1answer
20k views

get product attributes for current product and store it in a variable

Been trying to figure out how I can get the product attributes of the current product and store it in a variable and put it in a class. I've managed to get the product attributes, unfortunately it ...
3
votes
3answers
7k views

Facebook Comment Count

I am a bit of an amateur when it comes to PHP and WordPress but I have rigged up the following code: function fb_comment_count($url = 'some url here') { $filecontent = file_get_contents('https://...
3
votes
1answer
1k views

Enforcing password complexity

We need to enforce password complexity in a wordpress site, we used this article: http://www.webtipblog.com/force-password-complexity-requirements-wordpress/ We created the following in functions....
3
votes
2answers
1k views

Calculate percentage of post by category

Is it possible to calculate the percentage of posts in each given category? I'd like to make a bar chart to visualize the amout of posts in those categories. I thought what one needs would be the ...
3
votes
1answer
2k views

Getting paginate_links() 'end_size' to display none

I'm working with the paginate_links() function and I'm trying to create a pagination in this kind of style; < 3 4 5 6 7 > Logically I thought it would be simple by setting end_size to 0 and ...
3
votes
1answer
6k views

wp_customize_image_control default value

I am trying to create a custom theme using Wordpress 3.4's customization options. I would like to create an option to change the theme's logo, but I would like to also display a default logo image. ...
3
votes
3answers
3k views

Integrating WordPress to my website, while keeping my own authentication system

I've recently integrated WordPress to my website and I've been trying to find out the correct way to replace Wordpress' authentication system with the one on my website. My website already has a user ...
3
votes
1answer
5k views

Why is my custom meta box input not saving

I've added the following function to functions.php to add a custom meta box enabling the end user to input a gallery shortcode. I then intend to use this to place a gallery in a specific place on the ...
3
votes
1answer
1k views

How to find cause of PHP notices with no stack trace?

My WordPress debug.log is filling up with this group of seven PHP warnings/notices, recurring at least every half an hour... [08-Mar-2018 09:05:03 UTC] PHP Notice: Trying to get property of non-...
2
votes
1answer
7k views

How do I create a drop down menu in a widget?

How do I create a simple dropdown menu with 3 options in a widget? I'm using $instance to do it. How would it look in a barebones widget?
2
votes
1answer
775 views

wordpress separate registration for different roles

When a user click on a link to register it should assign them a different role, and not the default role. I've tried this link but it doesnt seem to work. I've placed it in the functions.php. ...
2
votes
1answer
2k views

media_handle_upload weird thing

I am using a front end script to upload images , all works fine but recently i noticed the uploaded images are not saved in proper directory. My settings are to Organize my uploads into month- and ...
2
votes
2answers
7k views

Wrong UTC and local time only on wordpress

my wordpress shows the wrong time, UTC time on the picture should be 18:06:28 and localtime 15:06:28, so the UTC time is showed as local time, I use my own vps on digital ocean and time zone is ...
2
votes
2answers
2k views

Customizer Show/Hide Logo and Site Title

I've setup checkbox controls in my theme Customizer to show/hide the Logo and Site Title when they are checked/unchecked. By default, I want the Logo to display and the Site Title to be hidden. ...
2
votes
1answer
1k views

Use Filename for Alt and Title Tags

I currently name all of my image files like this: Earth the Blue Planet.jpg Which when uploaded gets changed to this: Earth-the-Blue-Planet.jpg I was wondering if it is possible to have the image'...
2
votes
2answers
4k views

How to stop loading multiple copies of jquery

My wordpress header.php and function.php is given below.please help me to modify my php code to stop problems due to loading jquery multiple times. My plugins and themes are loading jquery multiple ...
2
votes
3answers
4k views

How do I redirect all 404 errors of a specific post type to another URL?

I have a custom post type containing job listings, that is highly volatile. Jobs are frequently added and removed. Our analytics show that a lot of crawling errors are for detail pages of jobs that ...
2
votes
2answers
1k views

functions.php not adding css to website?

So I went through the forum to find a solution before I post a question, however I have yet to find it. I'm new to wordpress and I'm having a lot of fun learning on how to build my own website. ...
2
votes
1answer
3k views

Change slug with custom field

I want to change the slug of a post with a custom field. In example, if the custom field is "keyword" my post link will become: mysite.com/keyword. If the custom field is empty, i want to generate a ...
2
votes
2answers
3k views

WordPress Custom Page Template in a different directory

Is it possible to have a custom page template in a different folder? I'm setting up a little framework for WordPress that I can use over and over for themes and just for the sake of being tidy I want ...