Get a remote post ID via API given URL

The Posts endpoint accepts a slug parameter when querying for posts, so if you can get the slug from the URL, then you can make request to /wp-json/wp/v2/posts?slug=<slug>. So if the URL is http://example.com/hello-world/ and you know the slug is hello-world, then for example in JavaScript, you can do something like: fetch( ‘http://example.com/wp-json/wp/v2/posts?slug=hello-world’ ) .then( … Read more

How to properly print a 404 error without redirecton? (i.e. keeping the current URL)

You should be using a filter outside of your template for this: add_filter( ‘template_include’, ‘wpa62226_template_include’, 1, 1 ); function wpa62226_template_include( $template ){ if( is_page( ‘some-page’ ) ) : global $wp_query; $wp_query->set_404(); status_header( 404 ); $template = locate_template( ‘404.php’ ); endif; return $template; } Your code is executed before the template is loaded, so it becomes … Read more

I restricted wordpress by logged users. It’s possible exclude a page?

I wanted to restrict my website except a specific page. This is my solution: function restrict_access_if_logged_out(){ global $wp; if (!is_user_logged_in() && !is_home() && ($wp->query_vars[‘pagename’] != ‘name-of-page’) ){ $redirect = home_url() . ‘/wp-login.php?redirect_to=’ . esc_url($_SERVER[“HTTP_HOST”] . urlencode($_SERVER[“REQUEST_URI”])); wp_redirect( $redirect ); exit; } } Only I added this: && ($wp->query_vars[‘pagename’] != ‘name-of-page’) in IF clause and a … Read more

Remove admin menu

There are three ways to do this I guess. First, you could start with blocking all access to admin.php and then whitelist the pages they are allowed to browse. Unless your users are really restricted this may take a while to figure out. Second, you could use the built-in capability system of WP, removing capabilities … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)